home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / X11 / dox-9.1 / dox.c < prev    next >
C/C++ Source or Header  |  1995-06-22  |  80KB  |  2,955 lines

  1. /*
  2. ** 1994    Arthur David Olson
  3. **
  4. ** The X Consortium, and any party obtaining a copy of these files from
  5. ** the X Consortium, directly or indirectly, is granted, free of charge, a
  6. ** full and unrestricted irrevocable, world-wide, paid up, royalty-free,
  7. ** nonexclusive right and license to deal in this software and
  8. ** documentation files (the "Software"), including without limitation the
  9. ** rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. ** and/or sell copies of the Software, and to permit persons who receive
  11. ** copies from any such party to do so.  This license includes without
  12. ** limitation a license to do the foregoing actions under any patents of
  13. ** the party supplying this software to the X Consortium.
  14. */
  15.  
  16. #include "stdio.h"
  17. #include "ctype.h"
  18. #include "errno.h"
  19. #include "setjmp.h"
  20. #include "X11/Xos.h"
  21. #include "X11/Xlib.h"
  22. #include "X11/Xproto.h"
  23. #include "X11/cursorfont.h"
  24. #include "X11/Xmu/WinUtil.h"
  25.  
  26. #ifndef __STDC__
  27. #define const
  28. #endif /* !defined __STDC__ */
  29.  
  30. static const char    elsieid[] = "@(#)dox.c    9.1";
  31.  
  32. /*
  33. ** typedefs
  34. */
  35.  
  36. typedef struct {
  37.     const char * const    name;
  38.     const unsigned long    value;
  39. } nv_T;
  40.  
  41. typedef enum {
  42.     EXACT, LESSCOMMONHEAD, LESSCOMMONTAIL, WITHIN, ABBREVIATING
  43. } matchtype_T;
  44.  
  45. /*
  46. ** function declarations
  47. */
  48.  
  49. static void        aloha();
  50. static XArc *        arcs();
  51. static int        catcher();
  52. static int        chrhi();
  53. static int        chrlo();
  54. static Bool        ciequal();
  55. static int        doerror();
  56. static Bool        dump();
  57. static void *        erealloc();
  58. static char **        getfields();
  59. static char *        getline();
  60. static void        handle();
  61. static int        iae();
  62. static int        iaearg();
  63. static Atom        iat();
  64. static Bool        ibo();
  65. static unsigned        ibu();
  66. static unsigned int    ici();
  67. static Colormap        ico();
  68. static int        icparg();
  69. static int        ics();
  70. static int        icsarg();
  71. static int        icssarg();
  72. static Cursor        icu();
  73. static Drawable        idr();
  74. static int        ieqarg();
  75. static Font        ifo();
  76. static int        ifssarg();
  77. static int        ifu();
  78. static GC        igc();
  79. static int        ignore();
  80. static unsigned long    igcc();
  81. static int        igm();
  82. static int        iin();
  83. static int        ijs();
  84. static unsigned        ikbm();
  85. static KeyCode        ikc();
  86. static KeySym        iks();
  87. static KeySym        iksfunc();
  88. static long        ilofunc();
  89. static int        ils();
  90. static int        ipb();
  91. static Pixmap        ipi();
  92. static unsigned long    ipx();
  93. static int        isacarg();
  94. static int        isamarg();
  95. static int        iscdmarg();
  96. static long        isem();
  97. static int        isfrarg();
  98. static int        isfsarg();
  99. static int        ishead();
  100. static int        isifarg();
  101. static int        isn();
  102. static int        isncarg();
  103. static int        issmarg();
  104. static char *        ist();
  105. static Time        iti();
  106. static unsigned long    iuem();
  107. static unsigned        iui();
  108. static unsigned long    iul();
  109. static Window        iwi();
  110. static XID        ixi();
  111. int            main();
  112. static Bool        mull();
  113. static void        myCloseDisplay();
  114. static void        myDrawArcs();
  115. static void        myDrawLines();
  116. static void        myDrawPoints();
  117. static void        myDrawRectangles();
  118. static void        myDrawSegments();
  119. static void        myFillArcs();
  120. static void        myFillPolygon();
  121. static void        myFillRectangles();
  122. static void        myMaskEvent();
  123. static void        myNextEvent();
  124. static void        myPeekEvent();
  125. static void        myWindowEvent();
  126. static Window        namedwindow();
  127. static char *        nonnull();
  128. static void        o0xfunc();
  129. static void        oat();
  130. static void        obits();
  131. static void        obo();
  132. static void        oco();
  133. static void        odr();
  134. static void        oev();
  135. static void        ogc();
  136. static void        oin();
  137. static void        okc();
  138. static void        okeepco();
  139. static void        okeepcu();
  140. static void        okeepfo();
  141. static void        okeeppi();
  142. static void        okeepwi();
  143. static void        okeyvec();
  144. static void        oks();
  145. static void        olo();
  146. static void        oname();
  147. static void        ost();
  148. static void        ostat();
  149. static void        otag();
  150. static void        oti();
  151. static void        oul();
  152. static void        owi();
  153. static void        oxi();
  154. static void        oxifunc();
  155. static Window        pickwindow();
  156. static XPoint *        points();
  157. static XRectangle *    rectangles();
  158. static XSegment *    segments();
  159. static void        spnl();
  160. static void        strhi();
  161. static void        strlo();
  162. static unsigned long    sum();
  163. static int        try();
  164. static void        usage();
  165. static unsigned long    value();
  166. static int        valuefunc();
  167. static void        wild2exit();
  168. static XID        xifunc();
  169.  
  170. /*
  171. ** name/value tables
  172. */
  173.  
  174. static const nv_T    alloweventsarg[] = {        /* X.h */
  175. { "AllowEvents argument" },
  176. { "AsyncPointer",            AsyncPointer },
  177. { "SyncPointer",            SyncPointer },
  178. { "AsyncKeyboard",            AsyncKeyboard },
  179. { "SyncKeyboard",            SyncKeyboard },
  180. { "ReplayPointer",            ReplayPointer },
  181. { "ReplayKeyboard",            ReplayKeyboard },
  182. { "AsyncBoth",                AsyncBoth },
  183. { "SyncBoth",                SyncBoth },
  184. { NULL },
  185. };
  186.  
  187. static const nv_T    changepropertyarg[] = {        /* X.h */
  188. { "ChangeProperty argument",        8 },
  189. { "PropModeReplace",            PropModeReplace },
  190. { "PropModePrepend",            PropModePrepend },
  191. { "PropModeAppend",            PropModeAppend },
  192. { NULL }
  193. };
  194.  
  195. static const nv_T    changesavesetarg[] = {        /* X.h */
  196. { "ChangeSaveSet argument",        7 },
  197. { "SetModeInsert",            SetModeInsert },
  198. { "SetModeDelete",            SetModeDelete },
  199. { NULL }
  200. };
  201.  
  202. static const nv_T    circulatesubwindowsarg[] = {    /* X.h */
  203. { "CirculateSubwindows argument" },
  204. { "RaiseLowest",            RaiseLowest },
  205. { "LowerHighest",            LowerHighest },
  206. { NULL }
  207. };
  208.  
  209. static const nv_T    eventsqueuedarg[] = {        /* Xlib.h */
  210. { "EventsQueued argument",        6 },
  211. { "QueuedAlready",            QueuedAlready },
  212. { "QueuedAfterFlush",            QueuedAfterFlush },
  213. { "QueuedAfterReading",            QueuedAfterReading },
  214. { NULL }
  215. };
  216.  
  217. static const nv_T    forcescreensaverarg[] = {    /* X.h */
  218. { "ForceScreenSaver argument",        11 },
  219. { "ScreenSaverActive",            ScreenSaverActive },
  220. { "ScreenSaverReset",            ScreenSaverReset },
  221. { NULL }
  222. };
  223.  
  224. static const nv_T    setaccesscontrolarg[] = {    /* X.h */
  225. { "SetAccessControl argument",        (unsigned) -6 },
  226. { "EnableAccess",            EnableAccess },
  227. { "DisableAccess",            DisableAccess },
  228. { NULL }
  229. };
  230.  
  231. static const nv_T    setarcmodearg[] = {        /* X.h */
  232. { "SetArcMode argument",        3 },
  233. { "ArcChord",                ArcChord },
  234. { "ArcPieSlice",            ArcPieSlice },
  235. { NULL }
  236. };
  237.  
  238. static const nv_T    setclosedownmodearg[] = {    /* X.h */
  239. { "SetCloseDownMode argument" },
  240. { "DestroyAll",                DestroyAll },
  241. { "RetainPermanent",            RetainPermanent },
  242. { "RetainTemporary",            RetainTemporary },
  243. { NULL }
  244. };
  245.  
  246. static const nv_T    setfillrulearg[] = {        /* X.h */
  247. { "SetFillRule argument",        (unsigned) -4 },
  248. { "EvenOddRule",            EvenOddRule },
  249. { "WindingRule",            WindingRule },
  250. { NULL }
  251. };
  252.  
  253. static const nv_T    setfillstylearg[] = {        /* X.h */
  254. { "SetFillStyle argument",        4 },
  255. { "FillSolid",                FillSolid },
  256. { "FillTiled",                FillTiled },
  257. { "FillStippled",            FillStippled },
  258. { "FillOpaqueStippled",            FillOpaqueStippled },
  259. { NULL }
  260. };
  261.  
  262. static const nv_T    setinputfocusarg[] = {        /* X.h */
  263. { "SetInputFocus argument",        8 },
  264. { "RevertToParent",            RevertToParent },
  265. { "RevertToPointerRoot",        RevertToPointerRoot },
  266. { "RevertToNone",            RevertToNone },
  267. { NULL }
  268. };
  269.  
  270. static const nv_T    setsubwindowmodearg[] = {    /* X.h */
  271. { "SetSubwindowMode argument" },
  272. { "ClipByChildren",            ClipByChildren },
  273. { "IncludeInferiors",            IncludeInferiors },
  274. { NULL }
  275. };
  276.  
  277. static const nv_T    storenamedcolorarg[] = {    /* X.h */
  278. { "StoreNamedColor argument",        2 },
  279. { "DoRed",                DoRed },
  280. { "DoGreen",                DoGreen },
  281. { "DoBlue",                DoBlue },
  282. { NULL }
  283. };
  284.  
  285. static const nv_T    allowexposures[] = {        /* X.h */
  286. { "exposures name",            (unsigned) -9 },
  287. { "DontAllowExposures",            DontAllowExposures },
  288. { "AllowExposures",            AllowExposures },
  289. { "DontDefaultExposures",        DefaultExposures },
  290. { NULL }
  291. };
  292.  
  293. static const nv_T    buttons[] = {            /* X.h */
  294. { "button name" },
  295. { "AnyButton",                AnyButton },
  296. { "Button1",                Button1 },
  297. { "Button2",                Button2 },
  298. { "Button3",                Button3 },
  299. { "Button4",                Button4 },
  300. { "Button5",                Button5 },
  301. { NULL }
  302. };
  303.  
  304. static const nv_T    capstyles[] = {            /* X.h */
  305. { "cap-style name",            3 },
  306. { "CapNotLast",                CapNotLast },
  307. { "CapButt",                CapButt },
  308. { "CapRound",                CapRound },
  309. { "CapProjecting",            CapProjecting },
  310. { NULL }
  311. };
  312.  
  313. static const nv_T    colormapchanges[] = {        /* X.h */
  314. { "colormap-change name",        8 },
  315. { "ColormapInstalled",            ColormapInstalled },
  316. { "ColormapUninstalled",        ColormapUninstalled },
  317. { NULL }
  318. };
  319.  
  320. static const nv_T    configuremasks[] = {        /* X.h */
  321. { "configure-window mask",        2 },
  322. { "CWX",                CWX },
  323. { "CWY",                CWY },
  324. { "CWWidth",                CWWidth },
  325. { "CWHeight",                CWHeight },
  326. { "CWBorderWidth",            CWBorderWidth },
  327. { "CWSibling",                CWSibling },
  328. { "CWStackMode",            CWStackMode },
  329. { NULL }
  330. };
  331.  
  332. static const nv_T    eventmasks[] = {        /* X.h */
  333. { "event-mask name",            (unsigned) -4 },
  334. { "NoEventMask",            NoEventMask },
  335. { "KeyPressMask",            KeyPressMask },
  336. { "KeyReleaseMask",            KeyReleaseMask },
  337. { "ButtonPressMask",            ButtonPressMask },
  338. { "ButtonReleaseMask",            ButtonReleaseMask },
  339. { "EnterWindowMask",            EnterWindowMask },
  340. { "LeaveWindowMask",            LeaveWindowMask },
  341. { "PointerMotionMask",            PointerMotionMask },
  342. { "PointerMotionHintMask",        PointerMotionHintMask },
  343. { "Button1MotionMask",            Button1MotionMask },
  344. { "Button2MotionMask",            Button2MotionMask },
  345. { "Button3MotionMask",            Button3MotionMask },
  346. { "Button4MotionMask",            Button4MotionMask },
  347. { "Button5MotionMask",            Button5MotionMask },
  348. { "ButtonMotionMask",            ButtonMotionMask },
  349. { "KeymapStateMask",            KeymapStateMask },
  350. { "ExposureMask",            ExposureMask },
  351. { "VisibilityChangeMask",        VisibilityChangeMask },
  352. { "StructureNotifyMask",        StructureNotifyMask },
  353. { "ResizeRedirectMask",            ResizeRedirectMask },
  354. { "SubstructureNotifyMask",        SubstructureNotifyMask },
  355. { "SubstructureRedirectMask",        SubstructureRedirectMask },
  356. { "FocusChangeMask",            FocusChangeMask },
  357. { "PropertyChangeMask",            PropertyChangeMask },
  358. { "ColormapChangeMask",            ColormapChangeMask },
  359. { "OwnerGrabButtonMask",        OwnerGrabButtonMask },
  360. { NULL }
  361. };
  362.  
  363. static const nv_T    events[] = {            /* X.h */
  364. { "event name" },
  365. { "Error",                0 },
  366. { "Reply",                1 },
  367. { "KeyPress",                KeyPress },
  368. { "KeyRelease",                KeyRelease },
  369. { "ButtonPress",            ButtonPress },
  370. { "ButtonRelease",            ButtonRelease },
  371. { "MotionNotify",            MotionNotify },
  372. { "EnterNotify",            EnterNotify },
  373. { "LeaveNotify",            LeaveNotify },
  374. { "FocusIn",                FocusIn },
  375. { "FocusOut",                FocusOut },
  376. { "KeymapNotify",            KeymapNotify },
  377. { "Expose",                Expose },
  378. { "GraphicsExpose",            GraphicsExpose },
  379. { "NoExpose",                NoExpose },
  380. { "VisibilityNotify",            VisibilityNotify },
  381. { "CreateNotify",            CreateNotify },
  382. { "DestroyNotify",            DestroyNotify },
  383. { "UnmapNotify",            UnmapNotify },
  384. { "MapNotify",                MapNotify },
  385. { "MapRequest",                MapRequest },
  386. { "ReparentNotify",            ReparentNotify },
  387. { "ConfigureNotify",            ConfigureNotify },
  388. { "ConfigureRequest",            ConfigureRequest },
  389. { "GravityNotify",            GravityNotify },
  390. { "ResizeRequest",            ResizeRequest },
  391. { "CirculateNotify",            CirculateNotify },
  392. { "CirculateRequest",            CirculateRequest },
  393. { "PropertyNotify",            PropertyNotify },
  394. { "SelectionClear",            SelectionClear },
  395. { "SelectionRequest",            SelectionRequest },
  396. { "SelectionNotify",            SelectionNotify },
  397. { "ColormapNotify",            ColormapNotify },
  398. { "ClientMessage",            ClientMessage },
  399. { "MappingNotify",            MappingNotify },
  400. { NULL }
  401. };
  402.  
  403. static const nv_T    functions[] = {            /* X.h */
  404. { "function name",            2 },
  405. { "GXclear",                GXclear },
  406. { "GXand",                GXand },
  407. { "GXandReverse",            GXandReverse },
  408. { "GXcopy",                GXcopy },
  409. { "GXandInverted",            GXandInverted },
  410. { "GXnoop",                GXnoop },
  411. { "GXxor",                GXxor },
  412. { "GXor",                GXor },
  413. { "GXnor",                GXnor },
  414. { "GXequiv",                GXequiv },
  415. { "GXinvert",                GXinvert },
  416. { "GXorReverse",            GXorReverse },
  417. { "GXcopyInverted",            GXcopyInverted },
  418. { "GXorInverted",            GXorInverted },
  419. { "GXnand",                GXnand },
  420. { "GXset",                GXset },
  421. { NULL }
  422. };
  423.  
  424. static const nv_T    gccomponents[] = {        /* X.h */
  425. { "GC-component name",            2 },
  426. { "GCFunction",                GCFunction },
  427. { "GCPlaneMask",            GCPlaneMask },
  428. { "GCForeground",            GCForeground },
  429. { "GCBackground",            GCBackground },
  430. { "GCLineWidth",            GCLineWidth },
  431. { "GCLineStyle",            GCLineStyle },
  432. { "GCCapStyle",                GCCapStyle },
  433. { "GCJoinStyle",            GCJoinStyle },
  434. { "GCFillStyle",            GCFillStyle },
  435. { "GCFillRule",                GCFillRule },
  436. { "GCTile",                GCTile },
  437. { "GCStipple",                GCStipple },
  438. { "GCTileStipXOrigin",            GCTileStipXOrigin },
  439. { "GCTileStipYOrigin",            GCTileStipYOrigin },
  440. { "GCFont",                GCFont },
  441. { "GCSubwindowMode",            GCSubwindowMode },
  442. { "GCGraphicsExposures",        GCGraphicsExposures },
  443. { "GCClipXOrigin",            GCClipXOrigin },
  444. { "GCClipYOrigin",            GCClipYOrigin },
  445. { "GCClipMask",                GCClipMask },
  446. { "GCDashOffset",            GCDashOffset },
  447. { "GCDashList",                GCDashList },
  448. { "GCArcMode",                GCArcMode },
  449. { NULL }
  450. };
  451.  
  452. static const nv_T    grabmodes[] = {            /* X.h */
  453. { "grab-mode name",            8 },
  454. { "GrabModeSync",            GrabModeSync },
  455. { "GrabModeAsync",            GrabModeAsync },
  456. { NULL }
  457. };
  458.  
  459. static const nv_T    graphicsexposes[] = {        /* Xproto.h */
  460. { "expose name",            6 },
  461. { "X_CopyArea",                X_CopyArea },
  462. { "X_CopyPlane",            X_CopyPlane },
  463. { NULL }
  464. };
  465.  
  466. static const nv_T    joinstyles[] = {        /* X.h */
  467. { "join-style name",            4 },
  468. { "JoinMiter",                JoinMiter },
  469. { "JoinRound",                JoinRound },
  470. { "JoinBevel",                JoinBevel },
  471. { NULL }
  472. };
  473.  
  474. static const nv_T    keybutmasks[] = {        /* X.h */
  475. { "modifier name",            (unsigned) -4 },
  476. { "AnyModifier",            AnyModifier },
  477. { "ShiftMask",                ShiftMask },
  478. { "LockMask",                LockMask },
  479. { "ControlMask",            ControlMask },
  480. { "Mod1Mask",                Mod1Mask },
  481. { "Mod2Mask",                Mod2Mask },
  482. { "Mod3Mask",                Mod3Mask },
  483. { "Mod4Mask",                Mod4Mask },
  484. { "Mod5Mask",                Mod5Mask },
  485. { "Button1Mask",            Button1Mask },
  486. { "Button2Mask",            Button2Mask },
  487. { "Button3Mask",            Button3Mask },
  488. { "Button4Mask",            Button4Mask },
  489. { "Button5Mask",            Button5Mask },
  490. { NULL }
  491. };
  492.  
  493. static const nv_T    linestyles[] = {        /* X.h */
  494. { "line-style name",            4 },
  495. { "LineSolid",                LineSolid },
  496. { "LineOnOffDash",            LineOnOffDash },
  497. { "LineDoubleDash",            LineDoubleDash },
  498. { NULL }
  499. };
  500.  
  501. static const nv_T    mappings[] = {            /* X.h */
  502. { "mapping name",            7 },
  503. { "MappingModifier",            MappingModifier },
  504. { "MappingPointer",            MappingPointer },
  505. { "MappingKeyboard",            MappingKeyboard },
  506. { NULL }
  507. };
  508.  
  509. static const nv_T    notifies[] = {            /* X.h */
  510. { "notify-mode name",            6 },
  511. { "NotifyNormal",            NotifyNormal },
  512. { "NotifyGrab",                NotifyGrab },
  513. { "NotifyUngrab",            NotifyUngrab },
  514. { "NotifyWhileGrabbed",            NotifyWhileGrabbed },
  515. { NULL }
  516. };
  517.  
  518. static const nv_T    notifydetails[] = {        /* X.h */
  519. { "notify-detail name",            6 },
  520. { "NotifyAncestor",            NotifyAncestor },
  521. { "NotifyVirtual",            NotifyVirtual },
  522. { "NotifyInferior",            NotifyInferior },
  523. { "NotifyNonlinear",            NotifyNonlinear },
  524. { "NotifyNonlinearVirtual",        NotifyNonlinearVirtual },
  525. { "NotifyPointer",            NotifyPointer },
  526. { "NotifyPointerRoot",            NotifyPointerRoot },
  527. { "NotifyDetailNone",            NotifyDetailNone },
  528. { NULL }
  529. };
  530.  
  531. static const nv_T    places[] = {            /* X.h */
  532. { "place name",                7 },
  533. { "PlaceOnTop",                PlaceOnTop },
  534. { "PlaceOnBottom",            PlaceOnTop },
  535. { NULL }
  536. };
  537.  
  538. static const nv_T    preferblankings[] = {        /* X.h */
  539. { "prefer-blanking name",        (unsigned) -8 },
  540. { "DontPreferBlanking",            DontPreferBlanking },
  541. { "PreferBlanking",            PreferBlanking },
  542. { "DontDefaultBlanking",        DefaultBlanking },
  543. { NULL }
  544. };
  545.  
  546. static const nv_T    propertychanges[] = {        /* X.h */
  547. { "property-change name",        8 },
  548. { "PropertyNewValue",            PropertyNewValue },
  549. { "PropertyDelete",            PropertyDelete },
  550. { NULL }
  551. };
  552.  
  553. static const nv_T    visibilities[] = {        /* X.h */
  554. { "visibilty name",            10 },
  555. { "VisibilityUnobscured",        VisibilityUnobscured },
  556. { "VisibilityPartiallyObscured",    VisibilityPartiallyObscured },
  557. { "VisibilityFullyObscured",        VisibilityFullyObscured },
  558. { NULL }
  559. };
  560.  
  561. static const nv_T    requestcodes[] = {        /* Xproto.h */
  562. { "request code",            2 },
  563. { "X_CreateWindow",            X_CreateWindow },
  564. { "X_ChangeWindowAttributes",        X_ChangeWindowAttributes },
  565. { "X_GetWindowAttributes",        X_GetWindowAttributes },
  566. { "X_DestroyWindow",            X_DestroyWindow },
  567. { "X_DestroySubwindows",        X_DestroySubwindows },
  568. { "X_ChangeSaveSet",            X_ChangeSaveSet },
  569. { "X_ReparentWindow",            X_ReparentWindow },
  570. { "X_MapWindow",            X_MapWindow },
  571. { "X_MapSubwindows",            X_MapSubwindows },
  572. { "X_UnmapWindow",            X_UnmapWindow },
  573. { "X_UnmapSubwindows",            X_UnmapSubwindows },
  574. { "X_ConfigureWindow",            X_ConfigureWindow },
  575. { "X_CirculateWindow",            X_CirculateWindow },
  576. { "X_GetGeometry",            X_GetGeometry },
  577. { "X_QueryTree",            X_QueryTree },
  578. { "X_InternAtom",            X_InternAtom },
  579. { "X_GetAtomName",            X_GetAtomName },
  580. { "X_ChangeProperty",            X_ChangeProperty },
  581. { "X_DeleteProperty",            X_DeleteProperty },
  582. { "X_GetProperty",            X_GetProperty },
  583. { "X_ListProperties",            X_ListProperties },
  584. { "X_SetSelectionOwner",        X_SetSelectionOwner },
  585. { "X_GetSelectionOwner",        X_GetSelectionOwner },
  586. { "X_ConvertSelection",            X_ConvertSelection },
  587. { "X_SendEvent",            X_SendEvent },
  588. { "X_GrabPointer",            X_GrabPointer },
  589. { "X_UngrabPointer",            X_UngrabPointer },
  590. { "X_GrabButton",            X_GrabButton },
  591. { "X_UngrabButton",            X_UngrabButton },
  592. { "X_ChangeActivePointerGrab",        X_ChangeActivePointerGrab },
  593. { "X_GrabKeyboard",            X_GrabKeyboard },
  594. { "X_UngrabKeyboard",            X_UngrabKeyboard },
  595. { "X_GrabKey",                X_GrabKey },
  596. { "X_UngrabKey",            X_UngrabKey },
  597. { "X_AllowEvents",            X_AllowEvents },
  598. { "X_GrabServer",            X_GrabServer },
  599. { "X_UngrabServer",            X_UngrabServer },
  600. { "X_QueryPointer",            X_QueryPointer },
  601. { "X_GetMotionEvents",            X_GetMotionEvents },
  602. { "X_TranslateCoords",            X_TranslateCoords },
  603. { "X_WarpPointer",            X_WarpPointer },
  604. { "X_SetInputFocus",            X_SetInputFocus },
  605. { "X_GetInputFocus",            X_GetInputFocus },
  606. { "X_QueryKeymap",            X_QueryKeymap },
  607. { "X_OpenFont",                X_OpenFont },
  608. { "X_CloseFont",            X_CloseFont },
  609. { "X_QueryFont",            X_QueryFont },
  610. { "X_QueryTextExtents",            X_QueryTextExtents },
  611. { "X_ListFonts",            X_ListFonts },
  612. { "X_ListFontsWithInfo",        X_ListFontsWithInfo },
  613. { "X_SetFontPath",            X_SetFontPath },
  614. { "X_GetFontPath",            X_GetFontPath },
  615. { "X_CreatePixmap",            X_CreatePixmap },
  616. { "X_FreePixmap",            X_FreePixmap },
  617. { "X_CreateGC",                X_CreateGC },
  618. { "X_ChangeGC",                X_ChangeGC },
  619. { "X_CopyGC",                X_CopyGC },
  620. { "X_SetDashes",            X_SetDashes },
  621. { "X_SetClipRectangles",        X_SetClipRectangles },
  622. { "X_FreeGC",                X_FreeGC },
  623. { "X_ClearArea",            X_ClearArea },
  624. { "X_CopyArea",                X_CopyArea },
  625. { "X_CopyPlane",            X_CopyPlane },
  626. { "X_PolyPoint",            X_PolyPoint },
  627. { "X_PolyLine",                X_PolyLine },
  628. { "X_PolySegment",            X_PolySegment },
  629. { "X_PolyRectangle",            X_PolyRectangle },
  630. { "X_PolyArc",                X_PolyArc },
  631. { "X_FillPoly",                X_FillPoly },
  632. { "X_PolyFillRectangle",        X_PolyFillRectangle },
  633. { "X_PolyFillArc",            X_PolyFillArc },
  634. { "X_PutImage",                X_PutImage },
  635. { "X_GetImage",                X_GetImage },
  636. { "X_PolyText8",            X_PolyText8 },
  637. { "X_PolyText16",            X_PolyText16 },
  638. { "X_ImageText8",            X_ImageText8 },
  639. { "X_ImageText16",            X_ImageText16 },
  640. { "X_CreateColormap",            X_CreateColormap },
  641. { "X_FreeColormap",            X_FreeColormap },
  642. { "X_CopyColormapAndFree",        X_CopyColormapAndFree },
  643. { "X_InstallColormap",            X_InstallColormap },
  644. { "X_UninstallColormap",        X_UninstallColormap },
  645. { "X_ListInstalledColormaps",        X_ListInstalledColormaps },
  646. { "X_AllocColor",            X_AllocColor },
  647. { "X_AllocNamedColor",            X_AllocNamedColor },
  648. { "X_AllocColorCells",            X_AllocColorCells },
  649. { "X_AllocColorPlanes",            X_AllocColorPlanes },
  650. { "X_FreeColors",            X_FreeColors },
  651. { "X_StoreColors",            X_StoreColors },
  652. { "X_StoreNamedColor",            X_StoreNamedColor },
  653. { "X_QueryColors",            X_QueryColors },
  654. { "X_LookupColor",            X_LookupColor },
  655. { "X_CreateCursor",            X_CreateCursor },
  656. { "X_CreateGlyphCursor",        X_CreateGlyphCursor },
  657. { "X_FreeCursor",            X_FreeCursor },
  658. { "X_RecolorCursor",            X_RecolorCursor },
  659. { "X_QueryBestSize",            X_QueryBestSize },
  660. { "X_QueryExtension",            X_QueryExtension },
  661. { "X_ListExtensions",            X_ListExtensions },
  662. { "X_ChangeKeyboardMapping",        X_ChangeKeyboardMapping },
  663. { "X_GetKeyboardMapping",        X_GetKeyboardMapping },
  664. { "X_ChangeKeyboardControl",        X_ChangeKeyboardControl },
  665. { "X_GetKeyboardControl",        X_GetKeyboardControl },
  666. { "X_Bell",                X_Bell },
  667. { "X_ChangePointerControl",        X_ChangePointerControl },
  668. { "X_GetPointerControl",        X_GetPointerControl },
  669. { "X_SetScreenSaver",            X_SetScreenSaver },
  670. { "X_GetScreenSaver",            X_GetScreenSaver },
  671. { "X_ChangeHosts",            X_ChangeHosts },
  672. { "X_ListHosts",            X_ListHosts },
  673. { "X_SetAccessControl",            X_SetAccessControl },
  674. { "X_SetCloseDownMode",            X_SetCloseDownMode },
  675. { "X_KillClient",            X_KillClient },
  676. { "X_RotateProperties",            X_RotateProperties },
  677. { "X_ForceScreenSaver",            X_ForceScreenSaver },
  678. { "X_SetPointerMapping",        X_SetPointerMapping },
  679. { "X_GetPointerMapping",        X_GetPointerMapping },
  680. { "X_SetModifierMapping",        X_SetModifierMapping },
  681. { "X_GetModifierMapping",        X_GetModifierMapping },
  682. { "X_NoOperation",            X_NoOperation },
  683. { NULL }
  684. };
  685.  
  686. static const nv_T    cursors[] = {            /* cursorfont.h */
  687. { "cursor name",            3 },
  688. { "XC_X_cursor",            XC_X_cursor },
  689. { "XC_arrow",                XC_arrow },
  690. { "XC_based_arrow_down",        XC_based_arrow_down },
  691. { "XC_based_arrow_up",            XC_based_arrow_up },
  692. { "XC_boat",                XC_boat },
  693. { "XC_bogosity",            XC_bogosity },
  694. { "XC_bottom_left_corner",        XC_bottom_left_corner },
  695. { "XC_bottom_right_corner",        XC_bottom_right_corner },
  696. { "XC_bottom_side",            XC_bottom_side },
  697. { "XC_bottom_tee",            XC_bottom_tee },
  698. { "XC_box_spiral",            XC_box_spiral },
  699. { "XC_center_ptr",            XC_center_ptr },
  700. { "XC_circle",                XC_circle },
  701. { "XC_clock",                XC_clock },
  702. { "XC_coffee_mug",            XC_coffee_mug },
  703. { "XC_cross",                XC_cross },
  704. { "XC_cross_reverse",            XC_cross_reverse },
  705. { "XC_crosshair",            XC_crosshair },
  706. { "XC_diamond_cross",            XC_diamond_cross },
  707. { "XC_dot",                XC_dot },
  708. { "XC_dotbox",                XC_dotbox },
  709. { "XC_double_arrow",            XC_double_arrow },
  710. { "XC_draft_large",            XC_draft_large },
  711. { "XC_draft_small",            XC_draft_small },
  712. { "XC_draped_box",            XC_draped_box },
  713. { "XC_exchange",            XC_exchange },
  714. { "XC_fleur",                XC_fleur },
  715. { "XC_gobbler",                XC_gobbler },
  716. { "XC_gumby",                XC_gumby },
  717. { "XC_hand1",                XC_hand1 },
  718. { "XC_hand2",                XC_hand2 },
  719. { "XC_heart",                XC_heart },
  720. { "XC_icon",                XC_icon },
  721. { "XC_iron_cross",            XC_iron_cross },
  722. { "XC_left_ptr",            XC_left_ptr },
  723. { "XC_left_side",            XC_left_side },
  724. { "XC_left_tee",            XC_left_tee },
  725. { "XC_leftbutton",            XC_leftbutton },
  726. { "XC_ll_angle",            XC_ll_angle },
  727. { "XC_lr_angle",            XC_lr_angle },
  728. { "XC_man",                XC_man },
  729. { "XC_middlebutton",            XC_middlebutton },
  730. { "XC_mouse",                XC_mouse },
  731. { "XC_pencil",                XC_pencil },
  732. { "XC_pirate",                XC_pirate },
  733. { "XC_plus",                XC_plus },
  734. { "XC_question_arrow",            XC_question_arrow },
  735. { "XC_right_ptr",            XC_right_ptr },
  736. { "XC_right_side",            XC_right_side },
  737. { "XC_right_tee",            XC_right_tee },
  738. { "XC_rightbutton",            XC_rightbutton },
  739. { "XC_rtl_logo",            XC_rtl_logo },
  740. { "XC_sailboat",            XC_sailboat },
  741. { "XC_sb_down_arrow",            XC_sb_down_arrow },
  742. { "XC_sb_h_double_arrow",        XC_sb_h_double_arrow },
  743. { "XC_sb_left_arrow",            XC_sb_left_arrow },
  744. { "XC_sb_right_arrow",            XC_sb_right_arrow },
  745. { "XC_sb_up_arrow",            XC_sb_up_arrow },
  746. { "XC_sb_v_double_arrow",        XC_sb_v_double_arrow },
  747. { "XC_shuttle",                XC_shuttle },
  748. { "XC_sizing",                XC_sizing },
  749. { "XC_spider",                XC_spider },
  750. { "XC_spraycan",            XC_spraycan },
  751. { "XC_star",                XC_star },
  752. { "XC_target",                XC_target },
  753. { "XC_tcross",                XC_tcross },
  754. { "XC_top_left_arrow",            XC_top_left_arrow },
  755. { "XC_top_left_corner",            XC_top_left_corner },
  756. { "XC_top_right_corner",        XC_top_right_corner },
  757. { "XC_top_side",            XC_top_side },
  758. { "XC_top_tee",                XC_top_tee },
  759. { "XC_trek",                XC_trek },
  760. { "XC_ul_angle",            XC_ul_angle },
  761. { "XC_umbrella",            XC_umbrella },
  762. { "XC_ur_angle",            XC_ur_angle },
  763. { "XC_watch",                XC_watch },
  764. { "XC_xterm",                XC_xterm },
  765. { NULL }
  766. };
  767.  
  768. static const nv_T    shapes[] = {            /* X.h */
  769. { "shape" },
  770. { "Complex",                Complex },
  771. { "Convex",                Convex },
  772. { "Nonconvex",                Nonconvex },
  773. { NULL }
  774. };
  775.  
  776. static const nv_T    coordmodes[] = {        /* X.h */
  777. { "coordinate-mode value",        9 },
  778. { "CoordModeOrigin",            CoordModeOrigin },
  779. { "CoordModePrevious",            CoordModePrevious },
  780. { NULL }
  781. };
  782.  
  783. /*
  784. ** Other global variables.
  785. */
  786.  
  787. static Display *    display;
  788. static int        default_screen_number;
  789. static Window        default_root_window;
  790. static GC        default_gc;
  791. static Colormap        default_colormap;
  792. static unsigned long    black_pixel;
  793. static unsigned long    white_pixel;
  794.  
  795. static const char *    progname;
  796.  
  797. static const char *    argfuncname;
  798. static char *        testfuncname;
  799.  
  800. static Bool        intflag;
  801. static Bool        frameflag;
  802. static Bool        verboseflag;
  803.  
  804. static Bool        single;
  805. static Bool        interactive;
  806.  
  807. static jmp_buf        env;
  808.  
  809. /*
  810. ** Error handling.
  811. */
  812.  
  813. static void
  814. aloha()
  815. {
  816.     /*
  817.     ** Is this the end, or is it only. . .
  818.     */
  819.     if (interactive)
  820.         longjmp(env, 0);
  821.     if (display != NULL)
  822.         XCloseDisplay(display);
  823.     exit(1);
  824. }
  825.  
  826. static void
  827. wild2exit(part1, part2)
  828. register const char * const    part1;
  829. register const char * const    part2;
  830. {
  831.     (void) fprintf(stderr, "\n%s: wild", progname);
  832.     if (part1 != NULL)
  833.         (void) fprintf(stderr, " %s", part1);
  834.     if (part2 != NULL)
  835.         (void) fprintf(stderr, " %s", part2);
  836.     (void) fprintf(stderr, "\n");
  837.     aloha();
  838. }
  839.  
  840. #define wildexit(message)    wild2exit((message), (char *) NULL)
  841. #define wildrexit(message)    wild2exit("result from", (message))
  842.  
  843. /*
  844. ** Memory management.
  845. */
  846.  
  847. static void *
  848. erealloc(pointer, size)
  849. register char * const    pointer;
  850. register int        size;
  851. {
  852.     register char * result;
  853.  
  854.     if (size == 0)
  855.         size = 1;
  856.     if (pointer == NULL)
  857.         result = (char *) malloc((unsigned int) size);
  858.     else    result = (char *) realloc((char *) pointer,
  859.             (unsigned int) size);
  860.     if (result == NULL) {
  861.         interactive = False;
  862.         wildrexit("getting memory");
  863.     }
  864.     return result;
  865. }
  866.  
  867. #define emalloc(size)    erealloc((char *) NULL, (size))
  868.  
  869. /*
  870. ** Character and string manipulation.
  871. */
  872.  
  873. static char *
  874. nonnull(cp)
  875. register char * cp;
  876. {
  877.     static char    null;
  878.  
  879.     return (cp == NULL) ? &null : cp;
  880. }
  881.  
  882. static int
  883. chrhi(c)
  884. register const int    c;
  885. {
  886.     return (isascii(c) && islower(c)) ? toupper(c) : c;
  887. }
  888.  
  889. static int
  890. chrlo(c)
  891. register const int    c;
  892. {
  893.     return (isascii(c) && isupper(c)) ? tolower(c) : c;
  894. }
  895.  
  896. static void
  897. strhi(cp)
  898. register char * cp;
  899. {
  900.     for ( ; *cp != '\0'; ++cp)
  901.         *cp = chrhi(*cp);
  902. }
  903.  
  904. static void
  905. strlo(cp)
  906. register char * cp;
  907. {
  908.     for ( ; *cp != '\0'; ++cp)
  909.         *cp = chrlo(*cp);
  910. }
  911.  
  912. static Bool
  913. ciequal(ap, bp)        /* case-insensitive equality */
  914. register const char *    ap;
  915. register const char *    bp;
  916. {
  917.     ap = nonnull(ap);
  918.     bp = nonnull(bp);
  919.     while (chrlo(*ap) == chrlo(*bp++))
  920.         if (*ap++ == '\0')
  921.             return True;
  922.     return False;
  923. }
  924.  
  925. #define csequal(ap, bp) ((Bool) (strcmp(nonnull(ap), nonnull(bp)) == 0))
  926.  
  927. /*
  928. ** Output side primitives.
  929. */
  930.  
  931. static void
  932. spnl(donl)
  933. register const Bool    donl;
  934. {
  935.     static Bool    did_output;
  936.  
  937.     if (donl) {
  938.         if (did_output) {
  939.             (void) printf("\n");
  940.             did_output = False;
  941.         }
  942.     } else {
  943.         if (did_output)
  944.             (void) printf(" ");
  945.         else    did_output = True;
  946.     }
  947. }
  948.  
  949. #define separate()    spnl(False)
  950.  
  951. /*
  952. ** name/value functions
  953. */
  954.  
  955. static void
  956. oname(val, table)
  957. register unsigned long    val;
  958. register const nv_T *    table;
  959. {
  960.     register int    i;
  961.  
  962.     for (i = 1; table[i].name != NULL; ++i)
  963.         if (table[i].value == val) {
  964.             ost(table[i].name);
  965.             return;
  966.         }
  967.     oul(val);
  968. }
  969.  
  970. static void
  971. obits(val, table)
  972. register unsigned long        val;
  973. register const nv_T * const    table;
  974. {
  975.     register int    i;
  976.     register Bool    didbit;
  977.  
  978.     separate();
  979.     didbit = False;
  980.     for (i = 1; table[i].name != NULL; ++i)
  981.         if ((val & table[i].value) == table[i].value) {
  982.             val &= ~table[i].value;
  983.             if (didbit)
  984.                 (void) printf("+");
  985.             else    didbit = True;
  986.             (void) printf("%s", table[i].name);
  987.         }
  988.     if (!didbit || val != 0) {
  989.         if (didbit)
  990.             (void) printf("+");
  991.         o0xfunc((unsigned long) val);
  992.     }
  993. }
  994.  
  995. static int
  996. ishead(abbr, name)
  997. register const char *    abbr;
  998. register const char *    name;
  999. {
  1000.     while (*abbr != '\0')
  1001.         if (chrlo(*abbr++) != chrlo(*name++))
  1002.             return 0;
  1003.     return 1;
  1004. }
  1005.  
  1006. static int
  1007. valuefunc(abbr, name, mt, arg)
  1008. register const char *        abbr;
  1009. register const char *        name;
  1010. register const matchtype_T    mt;
  1011. register const int        arg;
  1012. {
  1013.     register const char *    cp;
  1014.     register int        c;
  1015.  
  1016.     switch (mt) {
  1017.         case EXACT:
  1018.             return ciequal(abbr, name);
  1019.         case LESSCOMMONHEAD:
  1020.             return ciequal(abbr, name + arg);
  1021.         case LESSCOMMONTAIL:
  1022.             while (*abbr != '\0')
  1023.                 if (chrlo(*abbr++) != chrlo(*name++))
  1024.                     return 0;
  1025.             return strlen(name) == -arg;
  1026.         case WITHIN:
  1027.             for (cp = name; *cp != '\0'; ++cp)
  1028.                 if (ishead(abbr, cp))
  1029.                     return 1;
  1030.             return 0;
  1031.         case ABBREVIATING:
  1032.             while ((c = chrlo(*abbr++)) != '\0')
  1033.                 do {
  1034.                     if (*name == '\0')
  1035.                         return 0;
  1036.                 } while (chrlo(*name++) != c);
  1037.             return 1;
  1038.         default:    /* "cannot happen" */
  1039.             for ( ; ; )
  1040.                 wildexit("call of valuefunc");
  1041.     }
  1042. }
  1043.  
  1044. static unsigned long
  1045. value(name, table)
  1046. register const char * const    name;
  1047. register const nv_T * const    table;
  1048. {
  1049.     register const nv_T *    tp;
  1050.     register const nv_T *    retp;
  1051.     register int        mt;
  1052.  
  1053.     for (mt = EXACT; mt <= ABBREVIATING; ++mt) {
  1054.         switch (mt) {
  1055.             case LESSCOMMONHEAD:
  1056.                 if ((int) table[0].value <= 0)
  1057.                     continue;
  1058.                 break;
  1059.             case LESSCOMMONTAIL:
  1060.                 if ((int) table[0].value >= 0)
  1061.                     continue;
  1062.                 break;
  1063.         }
  1064.         retp = NULL;
  1065.         for (tp = &table[1]; tp->name != NULL; ++tp)
  1066.             if (valuefunc(name, tp->name, mt,
  1067.                 (int) table[0].value))
  1068.                     if (mt == EXACT ||
  1069.                         mt == LESSCOMMONHEAD ||
  1070.                         mt == LESSCOMMONTAIL)
  1071.                             return tp->value;
  1072.                     else if (retp == NULL)
  1073.                         retp = tp;
  1074.                     else    break;
  1075.         if (retp == NULL)
  1076.             continue;
  1077.         if (tp->name == NULL)
  1078.             return retp->value;
  1079.         /*
  1080.         ** Ambiguous.
  1081.         */
  1082.         (void) fprintf(stderr,
  1083.             "%s: wild value for %s (%s)--matches both %s and %s\n",
  1084.             progname, table->name, name, retp->name, tp->name);
  1085.         for ( ; ; )
  1086.             aloha();
  1087.     }
  1088.     /*
  1089.     ** No match.
  1090.     */
  1091.     (void) fprintf(stderr, "%s: wild value for %s (%s)\n",
  1092.         progname, table->name, name);
  1093.     (void) fprintf(stderr, "%s: usable values are:", progname);
  1094.     for (tp = &table[1]; tp->name != NULL; ++tp)
  1095.         (void) fprintf(stderr, " %s", tp->name);
  1096.     (void) fprintf(stderr, "\n");
  1097.     for ( ; ; )
  1098.         aloha();
  1099. }
  1100.  
  1101. static unsigned long
  1102. sum(string, table)
  1103. register const char *        string;
  1104. register const nv_T * const    table;
  1105. {
  1106.     register unsigned long    result;
  1107.     register char *        cp;
  1108.  
  1109.     result = 0;
  1110.     while ((cp = strchr(string, '+')) != NULL) {
  1111.         *cp = '\0';
  1112.         result |= value(string, table);
  1113.         *cp = '+';
  1114.         string = ++cp;
  1115.     }
  1116.     return result | value(string, table);
  1117. }
  1118.  
  1119. /*
  1120. ** Balance of output side.
  1121. */
  1122.  
  1123. static void
  1124. o0xfunc(x)
  1125. register const unsigned long    x;
  1126. {
  1127.     if (intflag || x <= 9)
  1128.         (void) printf("%lu", x);
  1129.     else    (void) printf("0x%lx", (long) x);
  1130. }
  1131.  
  1132. static void
  1133. ost(string)
  1134. register const char *    string;
  1135. {
  1136.     register int    c;
  1137.  
  1138.     separate();
  1139.     string = nonnull(string);
  1140.     while ((c = *string++) != '\0')
  1141.         if (c == '\\')
  1142.             (void) printf("\\\\");
  1143.         else if (c == '\b')
  1144.             (void) printf("\\b");
  1145.         else if (c == '\f')
  1146.             (void) printf("\\f");
  1147.         else if (c == '\r')
  1148.             (void) printf("\\r");
  1149.         else if (c == '\v')
  1150.             (void) printf("\\v");
  1151.         else if (isascii(c) && (isprint(c) || strchr(" \t\n", c) != 0))
  1152.             (void) printf("%c", c);
  1153.         else (void) printf("\\%03o", (unsigned char) c);
  1154. }
  1155.  
  1156. #define FUNC(name, type, format)    static void \
  1157.                     name(x) \
  1158.                     register const type x; \
  1159.                     { \
  1160.                         separate(); \
  1161.                         (void) printf(format, x); \
  1162.                     }
  1163.  
  1164. FUNC(oin, int, "%d")
  1165. FUNC(olo, long, "%ld")
  1166. FUNC(oul, unsigned long, "%lu")
  1167.  
  1168. #undef FUNC
  1169.  
  1170. static void
  1171. oat(x)
  1172. register const Atom    x;
  1173. {
  1174.     ost(XGetAtomName(display, x));
  1175. }
  1176.  
  1177. static void
  1178. obo(x)
  1179. register const Bool    x;
  1180. {
  1181.     ost(x ? "True" : "False");
  1182. }
  1183.  
  1184. static void
  1185. oti(x)
  1186. register const Time    x;
  1187. {
  1188.     if (x == CurrentTime)
  1189.         ost("CurrentTime");
  1190.     else    oul((unsigned long) x);
  1191. }
  1192.  
  1193. static void
  1194. oxi(x)
  1195. register const XID    x;
  1196. {
  1197.     separate();
  1198.     o0xfunc((unsigned long) x);
  1199. }
  1200.  
  1201. static void
  1202. odr(x)
  1203. register const Drawable x;
  1204. {
  1205.     oxi((XID) x);
  1206. }
  1207.  
  1208. static void
  1209. okc(x)
  1210. register const KeyCode    x;
  1211. {
  1212.     oul((unsigned long) x);
  1213. }
  1214.  
  1215. static void
  1216. oxifunc(xid, keep)
  1217. register const XID    xid;
  1218. register const Bool    keep;
  1219. {
  1220.     if (keep && single)
  1221.         (void) XSetCloseDownMode(display, RetainPermanent);
  1222.     oxi(xid);
  1223. }
  1224.  
  1225. #define FUNC(name, type, flag)    static void \
  1226.                     name(x) \
  1227.                     register type x; { \
  1228.                         oxifunc((XID) x, flag); \
  1229.                     }
  1230.  
  1231. FUNC(oco, Colormap, False)
  1232. FUNC(okeepco, Colormap, True)
  1233. FUNC(okeepcu, Cursor, True)
  1234. FUNC(okeepfo, Font, True)
  1235. FUNC(ogc, GC, False)
  1236. FUNC(okeeppi, Pixmap, True)
  1237. FUNC(owi, Window, False)
  1238. FUNC(okeepwi, Window, True)
  1239.  
  1240. #undef FUNC
  1241.  
  1242. static void
  1243. oks(x)
  1244. register const KeySym    x;
  1245. {
  1246.     ost(XKeysymToString(x));
  1247. }
  1248.  
  1249. static void
  1250. ostat(status)
  1251. register const Status    status;
  1252. {
  1253.     oin((int) status);
  1254. }
  1255.  
  1256. #define BYTES_PER_KEYMAP_VECTOR 32
  1257. #define BITS_PER_KEYMAP_BYTE    8
  1258.  
  1259. static void
  1260. okeyvec(vector)
  1261. const char    vector[BYTES_PER_KEYMAP_VECTOR];
  1262. {
  1263.     register int    bytenum;
  1264.     register int    bitnum;
  1265.     register int    did_output;
  1266.  
  1267.     separate();
  1268.     did_output = False;
  1269.     for (bytenum = 0; bytenum < BYTES_PER_KEYMAP_VECTOR; ++bytenum)
  1270.         for (bitnum = 0; bitnum < BITS_PER_KEYMAP_BYTE; ++bitnum)
  1271.             if ((vector[bytenum] & (1 << bitnum)) != 0) {
  1272.                 if (did_output)
  1273.                     (void) printf("+");
  1274.                 else    did_output = True;
  1275.                 (void) printf("%d",
  1276.                     bytenum * BITS_PER_KEYMAP_BYTE +
  1277.                     bitnum);
  1278.             }
  1279.     if (!did_output)
  1280.         (void) printf("None");    /* for lack of anything better */
  1281. }
  1282.  
  1283. static void
  1284. otag(tag)
  1285. register const char * const    tag;
  1286. {
  1287.     if (verboseflag)
  1288.         ost(tag);
  1289. }
  1290.  
  1291. #define otat(tag, val)        (otag(tag), oat(val))
  1292. #define otbits(tag, val, table) (otag(tag), obits((val), (table)))
  1293. #define otbo(tag, val)        (otag(tag), obo(val))
  1294. #define otco(tag, val)        (otag(tag), oco(val))
  1295. #define otdr(tag, val)        (otag(tag), odr(val))
  1296. #define otin(tag, val)        (otag(tag), oin(val))
  1297. #define otkc(tag, val)        (otag(tag), okc(val))
  1298. #define otkeyvec(tag, val)    (otag(tag), okeyvec(val))
  1299. #define otlo(tag, val)        (otag(tag), olo(val))
  1300. #define otname(tag, val, table) (otag(tag), oname((val), (table)))
  1301. #define otst(tag, val)        (otag(tag), ost(val))
  1302. #define otti(tag, val)        (otag(tag), oti(val))
  1303. #define trul(tag, val)        (otag(tag), oul(val))
  1304. #define otxi(tag, val)        (otag(tag), oxi(val))
  1305. #define otwi(tag, val)        (otag(tag), owi(val))
  1306.  
  1307. static void
  1308. oev(e)
  1309. const XEvent    e;
  1310. {
  1311.     oname((unsigned long) e.type, events);
  1312.     if (e.type == X_Error) {
  1313.         char    buf[512];
  1314.  
  1315.         otxi("resourceid", e.xerror.resourceid);
  1316.         trul("serial", e.xerror.serial);
  1317.         (void) XGetErrorText(display, e.xerror.error_code,
  1318.             buf, sizeof buf);
  1319.         otst("error_code", buf);
  1320.         otname("request_code",
  1321.             (unsigned long) e.xerror.request_code, requestcodes);
  1322.         otin("minor_code", (int) e.xerror.minor_code);
  1323.         return;
  1324.     }
  1325.     trul("serial", e.xany.serial);
  1326.     otbo("send_event", e.xany.send_event);
  1327.     /*
  1328.     trvp("display", (void *) e.xany.display);
  1329.     */
  1330.     switch (e.type) {
  1331.         case KeyPress:
  1332.         case KeyRelease:
  1333.             otwi("window", e.xkey.window);
  1334.             otwi("root", e.xkey.root);
  1335.             otwi("subwindow", e.xkey.subwindow);
  1336.             otti("time", e.xkey.time);
  1337.             otin("x", e.xkey.x);
  1338.             otin("y", e.xkey.y);
  1339.             otin("x_root", e.xkey.x_root);
  1340.             otin("y_root", e.xkey.y_root);
  1341.             otbits("state", (unsigned long) e.xkey.state,
  1342.                 keybutmasks);
  1343.             otkc("keycode", e.xkey.keycode);
  1344.             otbo("same_screen", e.xkey.same_screen);
  1345.             break;
  1346.         case ButtonPress:
  1347.         case ButtonRelease:
  1348.             otwi("window", e.xbutton.window);
  1349.             otwi("root", e.xbutton.root);
  1350.             otwi("subwindow", e.xbutton.subwindow);
  1351.             otti("time", e.xbutton.time);
  1352.             otin("x", e.xbutton.x);
  1353.             otin("y", e.xbutton.y);
  1354.             otin("x_root", e.xbutton.x_root);
  1355.             otin("y_root", e.xbutton.y_root);
  1356.             otbits("state", (unsigned long) e.xbutton.state,
  1357.                 keybutmasks);
  1358.             otname("button", (unsigned long) e.xbutton.button,
  1359.                 buttons);
  1360.             otbo("same_screen", e.xbutton.same_screen);
  1361.             break;
  1362.         case MotionNotify:
  1363.             otwi("window", e.xmotion.window);
  1364.             otwi("root", e.xmotion.root);
  1365.             otwi("subwindow", e.xmotion.subwindow);
  1366.             otti("time", e.xmotion.time);
  1367.             otin("x", e.xmotion.x);
  1368.             otin("y", e.xmotion.y);
  1369.             otin("x_root", e.xmotion.x_root);
  1370.             otin("y_root", e.xmotion.y_root);
  1371.             otbits("state", (unsigned long) e.xmotion.state,
  1372.                 keybutmasks);
  1373.             otbo("is_hint", (Bool) e.xmotion.is_hint);
  1374.             otbo("same_screen", e.xmotion.same_screen);
  1375.             break;
  1376.         case EnterNotify:
  1377.         case LeaveNotify:
  1378.             otwi("window", e.xcrossing.window);
  1379.             otwi("root", e.xcrossing.root);
  1380.             otwi("subwindow", e.xcrossing.subwindow);
  1381.             otti("time", e.xcrossing.time);
  1382.             otin("x", e.xcrossing.x);
  1383.             otin("y", e.xcrossing.y);
  1384.             otin("x_root", e.xcrossing.x_root);
  1385.             otin("y_root", e.xcrossing.y_root);
  1386.             otname("mode", (unsigned long) e.xcrossing.mode,
  1387.                 notifies);
  1388.             otname("detail", (unsigned long) e.xcrossing.detail,
  1389.                 notifydetails);
  1390.             otbo("same_screen", e.xcrossing.same_screen);
  1391.             otbo("focus", e.xcrossing.focus);
  1392.             otbits("state", (unsigned long) e.xcrossing.state,
  1393.                 keybutmasks);
  1394.             break;
  1395.         case FocusIn:
  1396.         case FocusOut:
  1397.             otwi("window", e.xfocus.window);
  1398.             otname("mode", (unsigned long) e.xfocus.mode,
  1399.                 notifies);
  1400.             otname("detail", (unsigned long) e.xfocus.detail,
  1401.                 notifydetails);
  1402.             break;
  1403.         case KeymapNotify:
  1404.             otwi("window", e.xkeymap.window);
  1405.             otkeyvec("key_vector", e.xkeymap.key_vector);
  1406.             break;
  1407.         case Expose:
  1408.             otwi("window", e.xexpose.window);
  1409.             otin("x", e.xexpose.x);
  1410.             otin("y", e.xexpose.y);
  1411.             otin("width", e.xexpose.width);
  1412.             otin("height", e.xexpose.height);
  1413.             otin("count", e.xexpose.count);
  1414.             break;
  1415.         case GraphicsExpose:
  1416.             otdr("drawable", e.xgraphicsexpose.drawable);
  1417.             otin("x", e.xgraphicsexpose.x);
  1418.             otin("y", e.xgraphicsexpose.y);
  1419.             otin("width", e.xgraphicsexpose.width);
  1420.             otin("height", e.xgraphicsexpose.height);
  1421.             otin("count", e.xgraphicsexpose.count);
  1422.             otname("major_code",
  1423.                 (unsigned long) e.xgraphicsexpose.major_code,
  1424.                 graphicsexposes);
  1425.             otin("minor_code", e.xgraphicsexpose.minor_code);
  1426.             break;
  1427.         case NoExpose:
  1428.             otdr("drawable", e.xnoexpose.drawable);
  1429.             otname("major_code",
  1430.                 (unsigned long) e.xnoexpose.major_code,
  1431.                 graphicsexposes);
  1432.             otin("minor_code", e.xnoexpose.minor_code);
  1433.             break;
  1434.         case VisibilityNotify:
  1435.             otwi("window", e.xvisibility.window);
  1436.             otname("state", (unsigned long) e.xvisibility.state,
  1437.                 visibilities);
  1438.             break;
  1439.         case CreateNotify:
  1440.             otwi("parent", e.xcreatewindow.parent);
  1441.             otwi("window", e.xcreatewindow.window);
  1442.             otin("x", e.xcreatewindow.x);
  1443.             otin("y", e.xcreatewindow.y);
  1444.             otin("width", e.xcreatewindow.width);
  1445.             otin("height", e.xcreatewindow.height);
  1446.             otin("border_width", e.xcreatewindow.border_width);
  1447.             otbo("override_redirect",
  1448.                 e.xcreatewindow.override_redirect);
  1449.             break;
  1450.         case DestroyNotify:
  1451.             otwi("event", e.xdestroywindow.event);
  1452.             otwi("window", e.xdestroywindow.window);
  1453.             break;
  1454.         case UnmapNotify:
  1455.             otwi("event", e.xunmap.event);
  1456.             otwi("window", e.xunmap.window);
  1457.             otbo("from_configure", e.xunmap.from_configure);
  1458.             break;
  1459.         case MapNotify:
  1460.             otwi("event", e.xmap.event);
  1461.             otwi("window", e.xmap.window);
  1462.             otbo("override_redirect", e.xmap.override_redirect);
  1463.             break;
  1464.         case MapRequest:
  1465.             otwi("parent", e.xmaprequest.parent);
  1466.             otwi("window", e.xmaprequest.window);
  1467.             break;
  1468.         case ReparentNotify:
  1469.             otwi("event", e.xreparent.event);
  1470.             otwi("window", e.xreparent.window);
  1471.             otwi("parent", e.xreparent.parent);
  1472.             otin("x", e.xreparent.x);
  1473.             otin("y", e.xreparent.y);
  1474.             otbo("override_redirect",
  1475.                 e.xreparent.override_redirect);
  1476.             break;
  1477.         case ConfigureNotify:
  1478.             otwi("event", e.xconfigure.event);
  1479.             otwi("window", e.xconfigure.window);
  1480.             otin("x", e.xconfigure.x);
  1481.             otin("y", e.xconfigure.y);
  1482.             otin("width", e.xconfigure.width);
  1483.             otin("height", e.xconfigure.height);
  1484.             otin("border_width", e.xconfigure.border_width);
  1485.             otwi("above", e.xconfigure.above);
  1486.             otbo("override_redirect",
  1487.                 e.xconfigure.override_redirect);
  1488.             break;
  1489.         case ConfigureRequest:
  1490.             otwi("parent", e.xconfigurerequest.parent);
  1491.             otwi("window", e.xconfigurerequest.window);
  1492.             otin("x", e.xconfigurerequest.x);
  1493.             otin("y", e.xconfigurerequest.y);
  1494.             otin("width", e.xconfigurerequest.width);
  1495.             otin("height", e.xconfigurerequest.height);
  1496.             otin("border_width", e.xconfigurerequest.border_width);
  1497.             otwi("above", e.xconfigurerequest.above);
  1498.             otin("detail", e.xconfigurerequest.detail);
  1499.             otbits("value_mask", e.xconfigurerequest.value_mask,
  1500.                 configuremasks);
  1501.             break;
  1502.         case GravityNotify:
  1503.             otwi("event", e.xgravity.event);
  1504.             otwi("window", e.xgravity.window);
  1505.             otin("x", e.xgravity.x);
  1506.             otin("y", e.xgravity.y);
  1507.             break;
  1508.         case ResizeRequest:
  1509.             otwi("window", e.xresizerequest.window);
  1510.             otin("width", e.xresizerequest.width);
  1511.             otin("height", e.xresizerequest.height);
  1512.             break;
  1513.         case CirculateNotify:
  1514.             otwi("event", e.xcirculate.event);
  1515.             otwi("window", e.xcirculate.window);
  1516.             otin("place", e.xcirculate.place);
  1517.             break;
  1518.         case CirculateRequest:
  1519.             otwi("parent", e.xcirculaterequest.parent);
  1520.             otwi("window", e.xcirculaterequest.window);
  1521.             otname("place",
  1522.                 (unsigned long) e.xcirculaterequest.place,
  1523.                 places);
  1524.             break;
  1525.         case PropertyNotify:
  1526.             otwi("window", e.xproperty.window);
  1527.             otat("atom", e.xproperty.atom);
  1528.             otti("time", e.xproperty.time);
  1529.             otname("state", (unsigned long) e.xproperty.state,
  1530.                 propertychanges);
  1531.             break;
  1532.         case SelectionClear:
  1533.             otwi("window", e.xselectionclear.window);
  1534.             otat("selection", e.xselectionclear.selection);
  1535.             otti("time", e.xselectionclear.time);
  1536.             break;
  1537.         case SelectionRequest:
  1538.             otwi("owner", e.xselectionrequest.owner);
  1539.             otwi("requestor", e.xselectionrequest.requestor);
  1540.             otat("selection", e.xselectionrequest.selection);
  1541.             otat("target", e.xselectionrequest.target);
  1542.             otat("property", e.xselectionrequest.property);
  1543.             otti("time", e.xselectionrequest.time);
  1544.             break;
  1545.         case SelectionNotify:
  1546.             otwi("requestor", e.xselection.requestor);
  1547.             otat("selection", e.xselection.selection);
  1548.             otat("target", e.xselection.target);
  1549.             otat("property", e.xselection.property);
  1550.             otti("time", e.xselection.time);
  1551.             break;
  1552.         case ColormapNotify:
  1553.             otwi("window", e.xcolormap.window);
  1554.             otco("colormap", e.xcolormap.colormap);
  1555.             otbo("new", e.xcolormap.new);
  1556.             otname("state", (unsigned long) e.xcolormap.state,
  1557.                 colormapchanges);
  1558.             break;
  1559.         case ClientMessage:
  1560.             otwi("window", e.xclient.window);
  1561.             otat("message_type", e.xclient.message_type);
  1562.             otin("format", e.xclient.format);
  1563.             (void) printf(" ");
  1564.             switch (e.xclient.format) {
  1565.                 register int        i;
  1566.                 register int        bytesper;
  1567.                 register int        n;
  1568.                 register unsigned long    val;
  1569.  
  1570.                 default:
  1571.                     (void) printf("?");
  1572.                     break;
  1573.                 case 8:
  1574.                 case 16:
  1575.                 case 32:
  1576.                     bytesper = e.xclient.format / 8;
  1577.                     n = 20 / bytesper;
  1578.                     for (i = 0; i < n; ++i) {
  1579.                         if (i != 0)
  1580.                             (void) printf(",");
  1581.                         val = (unsigned long)
  1582.                             ((bytesper == 1) ?
  1583.                             e.xclient.data.b[i] :
  1584.                             ((bytesper == 2) ?
  1585.                             e.xclient.data.s[i] :
  1586.                             e.xclient.data.l[i]));
  1587.                         (void) printf("%lu", val);
  1588.                     }
  1589.                     break;
  1590.             }
  1591.             break;
  1592.         case MappingNotify:
  1593.             otwi("window", e.xmapping.window);
  1594.             otname("request", (unsigned long) e.xmapping.request,
  1595.                 mappings);
  1596.             otkc("first_keycode",
  1597.                 (KeyCode) e.xmapping.first_keycode);
  1598.             otin("count", e.xmapping.count);
  1599.             break;
  1600.     }
  1601. }
  1602.  
  1603. /*
  1604. ** Input side--non-XID, non-mode stuff.
  1605. */
  1606.  
  1607. static char *
  1608. ist(cp)
  1609. register char * const    cp;
  1610. {
  1611.     return cp;
  1612. }
  1613.  
  1614. #define FUNC(name, type, fmt1, fmt2, mess) \
  1615.         static type \
  1616.         name(cp) \
  1617.         register const char * const    cp; \
  1618.         { \
  1619.             type    result; \
  1620.             char    dummy; \
  1621.             if (sscanf(cp, fmt1, &result) != 1 || \
  1622.                 sscanf(cp, fmt2, &result, &dummy) != 1) \
  1623.                     wild2exit(mess, cp); \
  1624.             return result; \
  1625.         }
  1626.  
  1627. FUNC(iin, int, "%i", "%i%c", "non-int argument")
  1628. FUNC(iui, unsigned int, "%u", "%u%c", "non-unsigned-int argument")
  1629. FUNC(iul, unsigned long, "%lu", "%lu%c", "non-unsigned-long argument")
  1630.  
  1631. #undef FUNC
  1632.  
  1633. static long
  1634. ilofunc(mess, cp)
  1635. register const char * const    mess;
  1636. register const char * const    cp;
  1637. {
  1638.     char *    ptr;
  1639.     long    result;
  1640.  
  1641.     result = strtol(cp, &ptr, 0);
  1642.     if (ptr == cp || *ptr != '\0')
  1643.         wild2exit(mess, cp);
  1644.     return result;
  1645. }
  1646.  
  1647. static Bool
  1648. ibo(cp)
  1649. register const char * const    cp;
  1650. {
  1651.     register long    result;
  1652.  
  1653.     if (ciequal(cp, "True") || ciequal(cp, "yes") || ciequal(cp, "on"))
  1654.         return True;
  1655.     if (ciequal(cp, "False") || ciequal(cp, "no") || ciequal(cp, "off"))
  1656.         return False;
  1657.     result = ilofunc("non-bool argument", cp);
  1658.     if (result != True && result != False)
  1659.         wild2exit("non-bool argument", cp);
  1660.     return result;
  1661. }
  1662.  
  1663. static unsigned long
  1664. ipx(cp)
  1665. register const char * const    cp;
  1666. {
  1667.     register long    result;
  1668.  
  1669.     if (ciequal(cp, "black") || ciequal(cp, "blackpixel"))
  1670.         return black_pixel;
  1671.     if (ciequal(cp, "white") || ciequal(cp, "whitepixel"))
  1672.         return white_pixel;
  1673.     result = ilofunc("non-pixel argument", cp);
  1674.     if (result != (unsigned long) result)
  1675.         wild2exit("non-pixel argument", cp);
  1676.     return result;
  1677. }
  1678.  
  1679. static KeyCode
  1680. ikc(cp)
  1681. register const char * const    cp;
  1682. {
  1683.     register long    result;
  1684.  
  1685.     result = ilofunc("non-keycode argument", cp);
  1686.     if ((KeyCode) result != result)
  1687.         wild2exit("non-keycode argument", cp);
  1688.     return result;
  1689. }
  1690.  
  1691. static int
  1692. isn(cp)
  1693. register const char * const    cp;
  1694. {
  1695.     if (ciequal(cp, "default") || ciequal(cp, "defaultscreen"))
  1696.         return default_screen_number;
  1697.     return iui(cp);
  1698. }
  1699.  
  1700. static KeySym
  1701. iksfunc(cp, oldks)
  1702. register const char * const    cp;
  1703. register KeySym            oldks;
  1704. {
  1705.     register KeySym newks;
  1706.  
  1707.     newks = XStringToKeysym(cp);
  1708.     if (newks == NoSymbol)
  1709.         return oldks;
  1710.     if (oldks != NoSymbol && oldks != newks)
  1711.         wild2exit("ambiguous keysym argument", cp);
  1712.     return newks;
  1713. }
  1714.  
  1715. static KeySym
  1716. iks(cp)
  1717. register const char * const    cp;
  1718. {
  1719.     register KeySym result;
  1720.     register char * buf;
  1721.     register char * dp;
  1722.     register char * tailp;
  1723.  
  1724.     /*
  1725.     ** Trivial way.
  1726.     */
  1727.     if (cp == NULL || *cp == '\0' || ciequal(cp, "NoSymbol"))
  1728.         return NoSymbol;
  1729.     /*
  1730.     ** Easy way.
  1731.     */
  1732.     result = XStringToKeysym(cp);
  1733.     if (result != NoSymbol)
  1734.         return result;
  1735.     /*
  1736.     ** Hard way.
  1737.     */
  1738.     buf = emalloc(strlen(cp) + 1);
  1739.     (void) strcpy(buf, cp);
  1740.     tailp = strchr(buf, '_');
  1741.     if (tailp != NULL)
  1742.         if (*++tailp == '\0')
  1743.             tailp = NULL;
  1744.     /*
  1745.     ** l..l (as in "dollar")
  1746.     */
  1747.     strlo(buf);
  1748.     result = XStringToKeysym(buf);
  1749.     /*
  1750.     ** Ul..l (as in "Home")
  1751.     */
  1752.     strlo(buf);
  1753.     *buf = chrhi(*buf);
  1754.     result = iksfunc(buf, result);
  1755.     /*
  1756.     ** Ul..lUl..l (as in "BackSpace")
  1757.     */
  1758.     strlo(buf);
  1759.     *buf = chrhi(*buf);
  1760.     for (dp = buf + 1; *dp != '\0'; ++dp) {
  1761.         *dp = chrhi(*dp);
  1762.         result = iksfunc(buf, result);
  1763.         *dp = chrlo(*dp);
  1764.     }
  1765.     /*
  1766.     ** l..l_U..U (as in "kana_YA")
  1767.     */
  1768.     if (tailp != NULL) {
  1769.         strlo(buf);
  1770.         strhi(tailp);
  1771.         result = iksfunc(buf, result);
  1772.     }
  1773.     /*
  1774.     ** U..U_Ul..l (as in "KP_Divide")
  1775.     */
  1776.     if (tailp != NULL) {
  1777.         strhi(buf);
  1778.         strlo(tailp + 1);
  1779.         result = iksfunc(buf, result);
  1780.     }
  1781.     /*
  1782.     ** Ul..l_U..Ul..l (as in "Shift_Lock" and "Greek_IOTAdiaeresis")
  1783.     */
  1784.     if (tailp != NULL) {
  1785.         strlo(buf);
  1786.         *buf = chrhi(*buf);
  1787.         for (dp = tailp; *dp != '\0'; ++dp) {
  1788.             *dp = chrhi(*dp);
  1789.             result = iksfunc(buf, result);
  1790.         }
  1791.     }
  1792.     if (result == NoSymbol)
  1793.         wild2exit("non-keysym argument", cp);
  1794.     return result;
  1795. }
  1796.  
  1797. /*ARGSUSED*/
  1798. static int
  1799. catcher(unused_display, unused_keep)
  1800. register const Display * const        unused_display;
  1801. register const XErrorEvent * const    unused_keep;
  1802. {
  1803.     return 0;
  1804. }
  1805.  
  1806. static Atom
  1807. iat(cp)
  1808. register const char * const    cp;
  1809. {
  1810.     register char * acp;
  1811.     register Atom    result;
  1812.     register Atom    an;
  1813.     register int (* oldhandler)();
  1814.  
  1815.     if ((result = XInternAtom(display, cp, True)) != 0)
  1816.         return result;
  1817.     oldhandler = XSetErrorHandler(catcher);
  1818.     for (an = 1; (acp = XGetAtomName(display, an)) != NULL; ++an)
  1819.         if (ciequal(cp, acp))
  1820.             if (result == 0)
  1821.                 result = an;
  1822.             else    wild2exit("multiple-match atom argument", cp);
  1823.     (void) XSetErrorHandler(oldhandler);
  1824.     if (result == 0)
  1825.         wild2exit("non-atom argument", cp);
  1826.     return result;
  1827. }
  1828.  
  1829. static Time
  1830. iti(cp)
  1831. register const char * const    cp;
  1832. {
  1833.     register long    result;
  1834.  
  1835.     if (ciequal(cp, "current") || ciequal(cp, "currenttime"))
  1836.         return CurrentTime;
  1837.     result = ilofunc("non-time argument", cp);
  1838.     if (result != (Time) result)
  1839.         wild2exit("non-time argument", cp);
  1840.     return result;
  1841. }
  1842.  
  1843. static unsigned int
  1844. ici(cp) /* cursor index */
  1845. register const char * const    cp;
  1846. {
  1847.     register long    result;
  1848.  
  1849.     if (strchr("0123456789", *nonnull(cp)) == NULL)
  1850.         return value(cp, cursors);
  1851.     result = ilofunc("non-cursor-index argument", cp);
  1852.     if (result != (unsigned int) result)
  1853.         wild2exit("non-cursor-index argument", cp);
  1854.     return result;
  1855. }
  1856.  
  1857. /*
  1858. ** Input side--XID stuff.
  1859. */
  1860.  
  1861. static Window
  1862. pickwindow()
  1863. {
  1864.     register Cursor cursor;
  1865.     register Window picked_win;
  1866.     register int    ndown;
  1867.     XEvent        pickevent;
  1868.  
  1869.     ndown = 0;
  1870.     picked_win = None;
  1871.     cursor = XCreateFontCursor(display, XC_crosshair);
  1872.     if (XGrabPointer(display, default_root_window, False,
  1873.         ButtonPressMask | ButtonReleaseMask, GrabModeSync,
  1874.         GrabModeAsync, None, cursor, CurrentTime) != GrabSuccess)
  1875.             wildexit("result grabbing pointer");
  1876.     while (picked_win == None || ndown != 0) {
  1877.         XAllowEvents(display, SyncPointer, CurrentTime);
  1878.         XWindowEvent(display, default_root_window,
  1879.             ButtonPressMask | ButtonReleaseMask, &pickevent);
  1880.         switch (pickevent.type) {
  1881.             case ButtonPress:
  1882.                 picked_win =
  1883.                     (pickevent.xbutton.subwindow == None) ?
  1884.                     default_root_window :
  1885.                     pickevent.xbutton.subwindow;
  1886.                 ++ndown;
  1887.                 break;
  1888.             case ButtonRelease:
  1889.                 if (ndown > 0)
  1890.                     --ndown;
  1891.                 break;
  1892.         }
  1893.     }
  1894.     XUngrabPointer(display, CurrentTime);
  1895.     XFlush(display);
  1896.     return frameflag ? picked_win : XmuClientWindow(display, picked_win);
  1897. }
  1898.  
  1899. static Window
  1900. namedwindow(name, topw, liberal)
  1901. register const char * const    name;
  1902. register const Window        topw;
  1903. register const Bool        liberal;
  1904. {
  1905.     Window *    children;
  1906.     Window        dummy;
  1907.     unsigned int    nchildren;
  1908.     int        i;
  1909.     Window        w;
  1910.     Window        neww;
  1911.     char *        window_name;
  1912.  
  1913.     w = 0;
  1914.     if (XFetchName(display, topw, &window_name) &&
  1915.         (liberal ? ciequal(window_name, name) :
  1916.         csequal(window_name, name)))
  1917.             w = topw;
  1918.     if (!XQueryTree(display, topw, &dummy, &dummy, &children, &nchildren))
  1919.         return w;
  1920.     for (i = 0; i < nchildren; ++i) {
  1921.         neww = namedwindow(name, children[i], liberal);
  1922.         if (neww == 0)
  1923.             continue;
  1924.         if (w == 0)
  1925.             w = neww;
  1926.         else    wild2exit("multiple windows matching name", name);
  1927.     }
  1928.     if (children)
  1929.         XFree((char *) children);
  1930.     return w;
  1931. }
  1932.  
  1933. /*ARGSUSED*/
  1934. static int
  1935. ignore(disp, eep)
  1936. Display *    disp;
  1937. XErrorEvent *    eep;
  1938. {
  1939.     return 0;
  1940. }
  1941.  
  1942. #define DOWINDOW    (1 << 1)
  1943. #define DOGC        (1 << 2)
  1944. #define DOCOLORMAP    (1 << 3)
  1945. #define DOCURSOR    (1 << 4)
  1946. #define DOFONT        (1 << 5)
  1947. #define DOPIXMAP    (1 << 6)
  1948. #define DODRAWABLE    (DOWINDOW | DOPIXMAP)
  1949. #define DOALL        (DOGC | DOCOLORMAP | DOCURSOR | DOFONT | DODRAWABLE)
  1950.  
  1951. static XID
  1952. xifunc(cp, flags, mess)
  1953. register const char * const    cp;
  1954. register const int        flags;
  1955. register const char * const    mess;
  1956. {
  1957.     register XID    result;
  1958.     register int    matches;
  1959.     long        l;
  1960.  
  1961.     result = 0;
  1962.     matches = 0;
  1963.     if (ciequal(cp, "none")) {
  1964.         result = (XID) None;
  1965.         ++matches;
  1966.     }
  1967.     if ((flags & DOWINDOW) != 0 && ciequal(cp, "+")) {
  1968.         result = (XID) pickwindow();
  1969.         ++matches;
  1970.     }
  1971.     if ((flags & DOWINDOW) != 0 &&
  1972.         (ciequal(cp, "root") ||
  1973.         ciequal(cp, "rootwindow") ||
  1974.         ciequal(cp, "defaultroot") ||
  1975.         ciequal(cp, "defaultrootwindow"))) {
  1976.             result = (XID) default_root_window;
  1977.             ++matches;
  1978.     }
  1979.     if ((flags & DOGC) != 0 &&
  1980.         (ciequal(cp, "default") || ciequal(cp, "defaultgc"))) {
  1981.             result = (XID) default_gc;
  1982.             ++matches;
  1983.     }
  1984.     if ((flags & DOCOLORMAP) != 0 &&
  1985.         (ciequal(cp, "default") || ciequal(cp, "defaultcolormap"))) {
  1986.             result = (XID) default_colormap;
  1987.             ++matches;
  1988.     }
  1989.     {
  1990.         char *    ptr;
  1991.  
  1992.         l = strtol(cp, &ptr, 0);
  1993.         if (ptr != cp && *ptr == '\0') {
  1994.             result = l;
  1995.             ++matches;
  1996.         }
  1997.     }
  1998.     if ((flags & DOWINDOW) != 0 && matches == 0) {
  1999.         register Bool    liberal;
  2000.         register Window newresult;
  2001.         register int (*    oldhandler)();
  2002.  
  2003.         /*
  2004.         ** We get to catch errors to avoid problems if a window
  2005.         ** disappears between a QueryTree and a FetchName.
  2006.         */
  2007.         oldhandler = XSetErrorHandler(ignore);
  2008.         for (liberal = False; liberal <= True; ++liberal) {
  2009.             newresult = (XID) namedwindow(cp, default_root_window,
  2010.                 liberal);
  2011.             if (newresult != 0) {
  2012.                 result = newresult;
  2013.                 ++matches;
  2014.                 break;
  2015.             }
  2016.         }
  2017.         (void) XSetErrorHandler(oldhandler);
  2018.     }
  2019.     if (matches > 1)
  2020.         wild2exit("ambiguous XID identifier", cp);
  2021.     if (flags == DOGC && result != (XID) default_gc)
  2022.         wildexit("GC argument");
  2023.     return result;
  2024. }
  2025.  
  2026. #define FUNC(name, type, flags, mess)    static type \
  2027.                     name(cp) \
  2028.                     register char * cp; \
  2029.                     { \
  2030.                         return (type) xifunc(cp, \
  2031.                             flags, mess); \
  2032.                     }
  2033.  
  2034. FUNC(ico, Colormap, DOCOLORMAP, "non-colormap argument")
  2035. FUNC(icu, Cursor, DOCURSOR, "non-cursor argument")
  2036. FUNC(idr, Drawable, DODRAWABLE, "non-drawable argument")
  2037. FUNC(ifo, Font, DOFONT, "non-font argument")
  2038. FUNC(igc, GC, DOGC, "non-gc argument")
  2039. FUNC(ipi, Pixmap, DOPIXMAP, "non-pixmap argument")
  2040. FUNC(iwi, Window, DOWINDOW, "non-window argument")
  2041. FUNC(ixi, XID, DOALL, "non-xid arugment")
  2042.  
  2043. #undef FUNC
  2044.  
  2045. /*
  2046. ** Input side--mode stuff.
  2047. */
  2048.  
  2049. #define FUNC(name, type, func, arg)    static type \
  2050.                     name(cp) \
  2051.                     register const char * const    cp; \
  2052.                     { \
  2053.                         return func(cp, arg); \
  2054.                     }
  2055.  
  2056. FUNC(iaearg, int, value, alloweventsarg)
  2057. FUNC(icparg, int, value, changepropertyarg)
  2058. FUNC(icsarg, int, value, circulatesubwindowsarg)
  2059. FUNC(icssarg, int, value, changesavesetarg)
  2060. FUNC(ieqarg, int, value, eventsqueuedarg)
  2061. FUNC(ifssarg, int, value, forcescreensaverarg)
  2062. FUNC(isacarg, int, value, setaccesscontrolarg)
  2063. FUNC(isamarg, int, value, setarcmodearg)
  2064. FUNC(iscdmarg, int, value, setclosedownmodearg)
  2065. FUNC(isfrarg, int, value, setfillrulearg)
  2066. FUNC(isfsarg, int, value, setfillstylearg)
  2067. FUNC(isifarg, int, value, setinputfocusarg)
  2068. FUNC(issmarg, int, value, setsubwindowmodearg)
  2069. FUNC(isncarg, int, value, storenamedcolorarg)
  2070.  
  2071. FUNC(iae, int, value, allowexposures)
  2072. FUNC(ibu, unsigned int, value, buttons)
  2073. FUNC(ics, int, value, capstyles)
  2074. FUNC(ifu, int, value, functions)
  2075. FUNC(igcc, unsigned long, sum, gccomponents)
  2076. FUNC(igm, int, value, grabmodes)
  2077. FUNC(ikbm, unsigned int, sum, keybutmasks)
  2078. FUNC(ijs, int, value, joinstyles)
  2079. FUNC(ils, int, value, linestyles)
  2080. FUNC(ipb, int, value, preferblankings)
  2081. /*
  2082. ** Why X11 has both signed and unsigned event_masks is beyond this writer.
  2083. */
  2084. FUNC(isem, long, sum, eventmasks)
  2085. FUNC(iuem, unsigned long, sum, eventmasks)
  2086.  
  2087. #undef FUNC
  2088.  
  2089. /*
  2090. ** Main course.
  2091. */
  2092.  
  2093. static const char * const *    v;
  2094. static int            n;
  2095.  
  2096. /*ARGSUSED*/
  2097. static Bool
  2098. dump(doname, descargs, unused_donum)
  2099. register const char * const    doname;
  2100. register const char * const    descargs;
  2101. register const int        unused_donum;
  2102. {
  2103.     (void) fprintf(stderr, " %s", doname);
  2104.     if (descargs != NULL && *descargs != '\0')
  2105.         (void) fprintf(stderr, " %s", descargs);
  2106.     (void) fprintf(stderr, "\n");
  2107.     return False;
  2108. }
  2109.  
  2110. static Bool
  2111. mull(doname, descargs, donum)
  2112. register const char * const    doname;
  2113. register const char * const    descargs;
  2114. register const int        donum;
  2115. {
  2116.     if (display == NULL)
  2117.         wildexit("function call with closed display");
  2118.     if (!csequal(doname, testfuncname))
  2119.         return False;
  2120.     if ((donum < 0) ? (n >= -donum) : (n == donum))
  2121.         return True;
  2122.     (void) fprintf(stderr, "%s: usage is", progname);
  2123.     if (single)
  2124.         (void) fprintf(stderr, " %s", progname);
  2125.     (void) dump(doname, descargs, donum);
  2126.     for ( ; ; )
  2127.         aloha();
  2128. }
  2129.  
  2130. static XArc *
  2131. arcs(strings, nstrings)
  2132. register char ** const    strings;
  2133. register const int    nstrings;
  2134. {
  2135.     register int    i;
  2136.     register int    narcs;    /* from the DEA? */
  2137.     static XArc *    result;
  2138.  
  2139.     if (nstrings < 0 || (nstrings % 6) != 0)
  2140.         wildexit("number of x/y/w/h/angle1/angle2 values");
  2141.     narcs = nstrings / 6;
  2142.     result = (XArc *) erealloc(result, narcs * sizeof *result);
  2143.     for (i = 0; i < narcs; ++i) {
  2144.         result[i].x = iin(strings[i * 6]);
  2145.         result[i].y = iin(strings[i * 6 + 1]);
  2146.         result[i].width = iui(strings[i * 6 + 2]);
  2147.         result[i].height = iui(strings[i * 6 + 3]);
  2148.         result[i].angle1 = iin(strings[i * 6 + 4]);
  2149.         result[i].angle2 = iin(strings[i * 6 + 5]);
  2150.     }
  2151.     return result;
  2152. }
  2153.  
  2154. static XPoint *
  2155. points(strings, nstrings)
  2156. register char ** const    strings;
  2157. register const int    nstrings;
  2158. {
  2159.     register int    i;
  2160.     register int    npoints;
  2161.     static XPoint * result;
  2162.  
  2163.     if (nstrings < 0 || (nstrings % 2) != 0)
  2164.         wildexit("number of x/y pairs");
  2165.     npoints = nstrings / 2;
  2166.     result = (XPoint *) erealloc(result, npoints * sizeof *result);
  2167.     for (i = 0; i < npoints; ++i) {
  2168.         result[i].x = iin(strings[i * 2]);
  2169.         result[i].y = iin(strings[i * 2 + 1]);
  2170.     }
  2171.     return result;
  2172. }
  2173.  
  2174. static XRectangle *
  2175. rectangles(strings, nstrings)
  2176. register char ** const    strings;
  2177. register const int    nstrings;
  2178. {
  2179.     register int        i;
  2180.     register int        nrects;
  2181.     static XRectangle *    result;
  2182.  
  2183.     if (nstrings < 0 || (nstrings % 4) != 0)
  2184.         wildexit("number of x/y/w/h values");
  2185.     nrects = nstrings / 4;
  2186.     result = (XRectangle *) erealloc(result, nrects * sizeof *result);
  2187.     for (i = 0; i < nrects; ++i) {
  2188.         result[i].x = iin(strings[i * 4]);
  2189.         result[i].y = iin(strings[i * 4 + 1]);
  2190.         result[i].width = iui(strings[i * 4 + 2]);
  2191.         result[i].height = iui(strings[i * 4 + 3]);
  2192.     }
  2193.     return result;
  2194. }
  2195.  
  2196. static XSegment *
  2197. segments(strings, nstrings)
  2198. register char ** const    strings;
  2199. register const int    nstrings;
  2200. {
  2201.     register int        i;
  2202.     register int        nsegs;
  2203.     static XSegment *    result;
  2204.  
  2205.     if (nstrings < 0 || (nstrings % 4) != 0)
  2206.         wildexit("number of x1/y1/x2/y2 values");
  2207.     nsegs = nstrings / 4;
  2208.     result = (XSegment *) erealloc(result, nsegs * sizeof *result);
  2209.     for (i = 0; i < nsegs; ++i) {
  2210.         result[i].x1 = iin(strings[i * 4]);
  2211.         result[i].y1 = iin(strings[i * 4 + 1]);
  2212.         result[i].x2 = iin(strings[i * 4 + 2]);
  2213.         result[i].y2 = iin(strings[i * 4 + 3]);
  2214.     }
  2215.     return result;
  2216. }
  2217.  
  2218. static void
  2219. myCloseDisplay(dpy)
  2220. register Display * const    dpy;
  2221. {
  2222.     XSync(dpy, False);
  2223.     XCloseDisplay(dpy);
  2224.     display = NULL;
  2225. }
  2226.  
  2227. static void
  2228. myDrawArcs(dpy, drawable, gc)
  2229. register Display * const    dpy;
  2230. register const Drawable        drawable;
  2231. register const GC        gc;
  2232. {
  2233.     XDrawArcs(dpy, drawable, gc, arcs(&v[2], n - 2), (n - 2) / 6);
  2234. }
  2235.  
  2236. static void
  2237. myDrawLines(dpy, drawable, gc)
  2238. register Display * const    dpy;
  2239. register const Drawable        drawable;
  2240. register const GC        gc;
  2241. {
  2242.     XDrawLines(dpy, drawable, gc, points(&v[2], n - 3), (n - 3) / 2,
  2243.         (int) value(v[n - 1], coordmodes));
  2244. }
  2245.  
  2246. static void
  2247. myDrawRectangles(dpy, drawable, gc)
  2248. register Display * const    dpy;
  2249. register const Drawable        drawable;
  2250. register const GC        gc;
  2251. {
  2252.     XDrawRectangles(dpy, drawable, gc,
  2253.         rectangles(&v[2], n - 2), (n - 2) / 4);
  2254. }
  2255.  
  2256. static void
  2257. myDrawSegments(dpy, drawable, gc)
  2258. register Display * const    dpy;
  2259. register const Drawable        drawable;
  2260. register const GC        gc;
  2261. {
  2262.     XDrawSegments(dpy, drawable, gc, segments(&v[2], n - 2), (n - 2) / 4);
  2263. }
  2264.  
  2265. static void
  2266. myDrawPoints(dpy, drawable, gc)
  2267. register Display * const    dpy;
  2268. register const Drawable        drawable;
  2269. register const GC        gc;
  2270. {
  2271.     XDrawPoints(dpy, drawable, gc, points(&v[2], n - 3), (n - 3) / 2,
  2272.         (int) value(v[n - 1], coordmodes));
  2273. }
  2274.  
  2275. static void
  2276. myFillArcs(dpy, drawable, gc)
  2277. register Display * const    dpy;
  2278. register const Drawable        drawable;
  2279. register const GC        gc;
  2280. {
  2281.     XFillArcs(dpy, drawable, gc, arcs(&v[2], n - 2), (n - 2) / 6);
  2282. }
  2283.  
  2284. static void
  2285. myFillPolygon(dpy, drawable, gc)    /* points.. shape mode */
  2286. register Display * const    dpy;
  2287. register const Drawable        drawable;
  2288. register const GC        gc;
  2289. {
  2290.     XFillPolygon(dpy, drawable, gc, points(&v[2], n - 4), (n - 4) / 2,
  2291.         (int) value(v[n - 2], shapes),
  2292.         (int) value(v[n - 1], coordmodes));
  2293. }
  2294.  
  2295. static void
  2296. myFillRectangles(dpy, drawable, gc)
  2297. register Display * const    dpy;
  2298. register const Drawable        drawable;
  2299. register const GC        gc;
  2300. {
  2301.     XFillRectangles(dpy, drawable, gc,
  2302.         rectangles(&v[2], n - 2), (n - 2) / 4);
  2303. }
  2304.  
  2305. static void
  2306. myMaskEvent(dpy, sem)
  2307. register Display * const    dpy;
  2308. register long            sem;
  2309. {
  2310.     static XEvent e;
  2311.  
  2312.     XMaskEvent(dpy, sem, &e);
  2313.     oev(e);
  2314. }
  2315.  
  2316. static void
  2317. myNextEvent(dpy)
  2318. register Display * const    dpy;
  2319. {
  2320.     static XEvent e;
  2321.  
  2322.     XNextEvent(dpy, &e);
  2323.     oev(e);
  2324. }
  2325.  
  2326. static void
  2327. myPeekEvent(dpy)
  2328. register Display * const    dpy;
  2329. {
  2330.     XEvent e;
  2331.  
  2332.     XPeekEvent(dpy, &e);
  2333.     oev(e);
  2334. }
  2335.  
  2336. static void
  2337. myWindowEvent(dpy, win, em)
  2338. register Display * const    dpy;
  2339. register Window            win;
  2340. register long            em;
  2341. {
  2342.     XEvent    e;
  2343.  
  2344.     XWindowEvent(dpy, win, em, &e);
  2345.     oev(e);
  2346. }
  2347.  
  2348. static int
  2349. try(testp)
  2350. register Bool (* const    testp)();
  2351. {
  2352.     register const char *    cp;
  2353.  
  2354.     cp = nonnull(argfuncname);
  2355.     if (testfuncname != NULL)
  2356.         free(testfuncname);
  2357.     testfuncname = emalloc(strlen(cp) + 1);
  2358.     (void) strcpy(testfuncname, cp + (chrlo(*cp) == 'x'));
  2359.     strlo(testfuncname);
  2360. #define L1(f0) \
  2361.         , f0(v[0])
  2362. #define L2(f0, f1) \
  2363.         L1(f0), f1(v[1])
  2364. #define L3(f0, f1, f2) \
  2365.         L2(f0, f1), f2(v[2])
  2366. #define L4(f0, f1, f2, f3) \
  2367.         L3(f0, f1, f2), f3(v[3])
  2368. #define L5(f0, f1, f2, f3, f4) \
  2369.         L4(f0, f1, f2, f3), f4(v[4])
  2370. #define L6(f0, f1, f2, f3, f4, f5) \
  2371.         L5(f0, f1, f2, f3, f4), f5(v[5])
  2372. #define L7(f0, f1, f2, f3, f4, f5, f6) \
  2373.         L6(f0, f1, f2, f3, f4, f5), f6(v[6])
  2374. #define L8(f0, f1, f2, f3, f4, f5, f6, f7) \
  2375.         L7(f0, f1, f2, f3, f4, f5, f6), f7(v[7])
  2376. #define L9(f0, f1, f2, f3, f4, f5, f6, f7, f8) \
  2377.         L8(f0, f1, f2, f3, f4, f5, f6, f7), f8(v[8])
  2378. #define L10(f0, f1, f2, f3, f4, f5, f6, f7, f8, f9) \
  2379.         L9(f0, f1, f2, f3, f4, f5, f6, f7, f8), f9(v[9])
  2380. #define PRE(name, func, dargs, r, num)    if ((*testp)(name, dargs, num)) { \
  2381.                         r(func(display
  2382. #define POST                        )); \
  2383.                         return True; \
  2384.                     }
  2385. #define DO(name, func, r) \
  2386.         PRE(name, func, (char *) NULL, r, 0) \
  2387.         POST
  2388. #define DO1(name, func, dargs, r, f0) \
  2389.         PRE(name, func, dargs, r, 1) \
  2390.         L1(f0) POST
  2391. #define DO2(name, func, dargs, r, f0, f1) \
  2392.         PRE(name, func, dargs, r, 2) \
  2393.         L2(f0, f1) POST
  2394. #define DO3(name, func, dargs, r, f0, f1, f2) \
  2395.         PRE(name, func, dargs, r, 3) \
  2396.         L3(f0, f1, f2) POST
  2397. #define DO4(name, func, dargs, r, f0, f1, f2, f3) \
  2398.         PRE(name, func, dargs, r, 4) \
  2399.         L4(f0, f1, f2, f3) POST
  2400. #define DO5(name, func, dargs, r, f0, f1, f2, f3, f4) \
  2401.         PRE(name, func, dargs, r, 5) \
  2402.         L5(f0, f1, f2, f3, f4) POST
  2403. #define DO6(name, func, dargs, r, f0, f1, f2, f3, f4, f5) \
  2404.         PRE(name, func, dargs, r, 6) \
  2405.         L6(f0, f1, f2, f3, f4, f5) POST
  2406. #define DO7(name, func, dargs, r, f0, f1, f2, f3, f4, f5, f6) \
  2407.         PRE(name, func, dargs, r, 7) \
  2408.         L7(f0, f1, f2, f3, f4, f5, f6) POST
  2409. #define DO8(name, func, dargs, r, f0, f1, f2, f3, f4, f5, f6, f7) \
  2410.         PRE(name, func, dargs, r, 8) \
  2411.         L8(f0, f1, f2, f3, f4, f5, f6, f7) POST
  2412. #define DO9(name, func, dargs, r, f0, f1, f2, f3, f4, f5, f6, f7, f8) \
  2413.         PRE(name, func, dargs, r, 9) \
  2414.         L9(f0, f1, f2, f3, f4, f5, f6, f7, f8) POST
  2415. #define DO10(name, func, dargs, r, f0, f1, f2, f3, f4, f5, f6, f7, f8, f9) \
  2416.         PRE(name, func, dargs, r, 10) \
  2417.         L10(f0, f1, f2, f3, f4, f5, f6, f7, f8, f9) POST
  2418. #define DO_2(name, func, dargs, r, f0, f1) \
  2419.         PRE(name, func, dargs, r, -2) \
  2420.         L2(f0, f1) POST
  2421.     switch (*testfuncname) {
  2422. default:
  2423. case 'a':
  2424.     DO("activatescreensaver", XActivateScreenSaver, (void));
  2425.     DO1("addtosaveset", XAddToSaveSet, "window", (void), iwi);
  2426.     DO2("allowevents", XAllowEvents,
  2427.         "event_mode time", (void), iaearg, iti);
  2428.     DO("autorepeatoff", XAutoRepeatOff, (void));
  2429.     DO("autorepeaton", XAutoRepeatOn, (void));
  2430. case 'b':
  2431.     DO1("bell", XBell, "percent", (void), iin);
  2432.     DO("bitmapbitorder", XBitmapBitOrder, oin);
  2433.     DO("bitmappad", XBitmapPad, oin);
  2434.     DO("bitmapunit", XBitmapUnit, oin);
  2435.     DO1("blackpixel", XBlackPixel, "screen_number", oul, isn);
  2436. case 'c':
  2437.     DO3("changeactivepointergrab", XChangeActivePointerGrab,
  2438.         "event_mask cursor time", (void), iuem, icu, iti);
  2439.     DO5("changepointercontrol", XChangePointerControl,
  2440. "do_accel do_threshold accel_numerator accel_denominator threshold",
  2441.         (void), ibo, ibo, iin, iin, iin);
  2442.     DO7("changeproperty", XChangeProperty,
  2443.         "window property type format mode data nelements",
  2444.         (void), iwi, iat, iat, iin, icparg,
  2445.         (unsigned char *) ist, iin);
  2446.     DO2("changesaveset", XChangeSaveSet,
  2447.         "window change_mode", (void), iwi, icssarg);
  2448.     DO2("circulatesubwindows", XCirculateSubwindows,
  2449.         "window direction", (void), iwi, icsarg);
  2450.     DO1("circulatesubwindowsdown", XCirculateSubwindowsDown,
  2451.         "window", (void), iwi);
  2452.     DO1("circulatesubwindowsup", XCirculateSubwindowsUp,
  2453.         "window", (void), iwi);
  2454.     DO6("cleararea", XClearArea,
  2455.         "window x y width height exposures",
  2456.         (void), iwi, iin, iin, iui, iui, ibo);
  2457.     DO1("clearwindow", XClearWindow, "window", (void), iwi);
  2458.     DO("closedisplay", myCloseDisplay, (void));
  2459.     DO("connectionnumber", XConnectionNumber, oin);
  2460.     DO5("convertselection", XConvertSelection,
  2461.         "selection target property requestor time",
  2462.         (void), iat, iat, iat, iwi, iti);
  2463.     DO9("copyarea", XCopyArea,
  2464.         "src dest gc src_x src_y width height dest_x dest_y",
  2465.         (void), idr, idr, igc, iin, iin, iui, iui, iin, iin);
  2466.     DO1("copycolormapandfree", XCopyColormapAndFree,
  2467.         "colormap", okeepco, ico);
  2468.     DO3("copygc", XCopyGC, "src valuemask dest", (void), igc, igcc, igc);
  2469.     DO10("copyplane", XCopyPlane,
  2470.         "src dest gc src_x src_y width height dest_x dest_y plane",
  2471.         (void), idr, idr, igc, iin, iin, iui, iui, iin, iin, iul);
  2472.     DO4("createbitmapfromdata", XCreateBitmapFromData,
  2473.         "drawable data width height", okeeppi, idr, ist, iui, iui);
  2474.     DO1("createfontcursor", XCreateFontCursor, "shape", okeepcu, ici);
  2475.     DO4("createpixmap", XCreatePixmap,
  2476.         "drawable width height depth", okeeppi, idr, iui, iui, iui);
  2477.     DO7("createpixmapfrombitmapdata", XCreatePixmapFromBitmapData,
  2478.         "drawable data width height fg bg depth",
  2479.         okeeppi, idr, ist, iui, iui, ipx, ipx, iui);
  2480.     DO8("createsimplewindow", XCreateSimpleWindow,
  2481.         "parent x y width height border_width border background",
  2482.         okeepwi, iwi, iin, iin, iui, iui, iui, ipx, ipx);
  2483. case 'd':
  2484.     DO1("defaultcolormap", XDefaultColormap, "screen_number", oco, isn);
  2485.     DO1("defaultdepth", XDefaultDepth, "screen_number", oin, isn);
  2486.     DO1("defaultgc", XDefaultGC, "screen_number", ogc, isn);
  2487.     DO("defaultrootwindow", XDefaultRootWindow, owi);
  2488.     DO("defaultscreen", XDefaultScreen, oin);
  2489.     DO2("definecursor", XDefineCursor, "window cursor", (void), iwi, icu);
  2490.     DO2("deleteproperty", XDeleteProperty,
  2491.         "window property", (void), iwi, iat);
  2492.     DO1("destroysubwindows", XDestroySubwindows, "window", (void), iwi);
  2493.     DO1("destroywindow", XDestroyWindow, "window", (void), iwi);
  2494.     DO("disableaccesscontrol", XDisableAccessControl, (void));
  2495.     DO1("displaycells", XDisplayCells, "screen_number", oin, isn);
  2496.     DO1("displayheight", XDisplayHeight, "screen_number", oin, isn);
  2497.     DO1("displayheightmm", XDisplayHeightMM, "screen_number", oin, isn);
  2498.     DO("displaymotionbuffersize", XDisplayMotionBufferSize, oul);
  2499.     DO1("displayplanes", XDisplayPlanes, "screen_number", oin, isn);
  2500.     DO("displaystring", XDisplayString, ost);
  2501.     DO1("displaywidth", XDisplayWidth, "screen_number", oin, isn);
  2502.     DO1("displaywidthmm", XDisplayWidthMM, "screen_number", oin, isn);
  2503.     DO8("drawarc", XDrawArc,
  2504.         "drawable gc x y width height angle1 angle2",
  2505.         (void), idr, igc, iin, iin, iui, iui, iin, iin);
  2506.     DO_2("drawarcs", myDrawArcs,
  2507.         "drawable gc [x y width height angle1 angle2 ...]",
  2508.         (void), idr, igc);
  2509.     DO6("drawimagestring", XDrawImageString,
  2510.         "drawable gc x y string length",
  2511.         (void), idr, igc, iin, iin, ist, iin);
  2512.     DO6("drawline", XDrawLine,
  2513.         "drawable gc x1 x2 y1 y2",
  2514.         (void), idr, igc, iin, iin, iin, iin);
  2515.     DO_2("drawlines", myDrawLines,
  2516.         "drawable gc [ x y ... ] mode", (void), idr, igc);
  2517.     DO4("drawpoint", XDrawPoint,
  2518.         "drawable gc x y", (void), idr, igc, iin, iin);
  2519.     DO_2("drawpoints", myDrawPoints,
  2520.         "drawable gc [ x y ... ] mode", (void), idr, igc);
  2521.     DO6("drawrectangle", XDrawRectangle,
  2522.         "drawable gc x y width height",
  2523.         (void), idr, igc, iin, iin, iui, iui);
  2524.     DO_2("drawrectangles", myDrawRectangles,
  2525.         "drawable gc [x y width height ...]", (void), idr, igc);
  2526.     DO_2("drawsegments", myDrawSegments,
  2527.         "drawable gc [x1 y1 x2 y2 ...]", (void), idr, igc);
  2528.     DO6("drawstring", XDrawString,
  2529.         "drawable gc x y string length",
  2530.         (void), idr, igc, iin, iin, ist, iin);
  2531. case 'e':
  2532.     DO("enableaccesscontrol", XEnableAccessControl, (void));
  2533.     DO1("eventsqueued", XEventsQueued, "mode", oin, ieqarg);
  2534. #if XlibSpecificationRelease - 6 >= 0
  2535.     DO("extendedmaxrequestsize", XExtendedMaxRequestSize, olo);
  2536. #endif /* XlibSpecificationRelease - 6 >= 0 */
  2537. case 'f':
  2538.     DO8("fillarc", XFillArc,
  2539.         "drawable gc x y width height angle1 angle2",
  2540.         (void), idr, igc, iin, iin, iui, iui, iin, iin);
  2541.     DO_2("fillarcs", myFillArcs,
  2542.         "drawable gc [x y width height angle1 angle2 ...]",
  2543.         (void), idr, igc);
  2544.     DO_2("fillpolygon", myFillPolygon,
  2545.         "drawable gc [ x y ... ] shape mode", (void), idr, igc);
  2546.     DO6("fillrectangle", XFillRectangle,
  2547.         "drawable gc x y width height",
  2548.         (void), idr, igc, iin, iin, iui, iui);
  2549.     DO_2("fillrectangles", myFillRectangles,
  2550.         "drawable gc [ x y width height ...]", (void), idr, igc);
  2551.     DO("flush", XFlush, (void));
  2552.     /*
  2553.     ** The next is conditionalized for the benefit of XV11R4 users
  2554.     ** (thanks to Jay Schmidgall <shmdgljd+@rchland.ibm.com>).
  2555.     */
  2556. #if XlibSpecificationRelease - 5 >= 0
  2557.     DO1("flushgc", XFlushGC, "gc", (void), igc);
  2558. #endif /* XlibSpecificationRelease - 5 >= 0 */
  2559.     DO1("forcescreensaver", XForceScreenSaver, "mode", (void), ifssarg);
  2560.     DO1("freecolormap", XFreeColormap, "colormap", (void), ico);
  2561.     DO1("freecursor", XFreeCursor, "cursor", (void), icu);
  2562.     DO1("freegc", XFreeGC, "gc", (void), igc);
  2563.     DO1("freepixmap", XFreePixmap, "pixmap", (void), ipi);
  2564. case 'g':
  2565.     /*
  2566.     ** No need to allow symbolic names as input here--
  2567.     ** if you knew the symbolic name, you would not need
  2568.     ** to call the function!
  2569.     */
  2570.     DO1("getatomname", XGetAtomName, "atom", ost, (Atom) iui);
  2571.     DO2("getdefault", XGetDefault, "program option", ost, ist, ist);
  2572.     DO1("getselectionowner", XGetSelectionOwner, "selection", owi, iat);
  2573.     {
  2574.         static char    gbdesc[] = "\
  2575. button modifiers grab_window owner_events event_mask \
  2576. pointer_mode keyboard_mode confine_to cursor";
  2577.  
  2578.     DO9("grabbutton", XGrabButton,
  2579.         gbdesc, (void), ibu, ikbm, iwi, ibo, iuem, igm, igm, iwi, icu);
  2580.     }
  2581.     DO6("grabkey", XGrabKey,
  2582. "keycode modifiers grab_window owner_events pointer_mode keyboard_mode",
  2583.         (void), iin, ikbm, iwi, ibo, igm, igm);
  2584.     DO5("grabkeyboard", XGrabKeyboard,
  2585.         "grab_window owner_events pointer_mode keyboard_mode time",
  2586.         oin, iwi, ibo, igm, igm, iti);
  2587.     {
  2588.         static char    gpdesc[] = "\
  2589. grab_window owner_events event_mask pointer_mode \
  2590. keyboard_mode confine_to cursor time";
  2591.  
  2592.     DO8("grabpointer", XGrabPointer,
  2593.         gpdesc, oin, iwi, ibo, iuem, igm, igm, iwi, icu, iti);
  2594.     }
  2595.     DO("grabserver", XGrabServer, (void));
  2596. case 'i':
  2597.     DO2("iconifywindow", XIconifyWindow,
  2598.         "window screen_number", ostat, iwi, isn);
  2599.     DO("imagebyteorder", XImageByteOrder, oin);
  2600.     DO1("installcolormap", XInstallColormap, "colormap", (void), ico);
  2601.     DO2("internatom", (int) XInternAtom,
  2602.         "atom_name only_if_exists", oin, ist, ibo);
  2603. case 'k':
  2604.     /*
  2605.     ** Don't ask.
  2606.     */
  2607. #ifdef NeedWidePrototypes
  2608.     DO2("keycodetokeysym", XKeycodeToKeysym,
  2609.         "keycode index", oks, (unsigned int) ikc, iin);
  2610. #endif /* defined NeedWidePrototypes */
  2611. #ifndef NeedWidePrototypes
  2612.     DO2("keycodetokeysym", XKeycodeToKeysym,
  2613.         "keycode index", oks, ikc, iin);
  2614. #endif /* !defined NeedWidePrototypes */
  2615.     DO1("keysymtokeycode", XKeysymToKeycode, "keysym", okc, iks);
  2616.     DO1("killclient", XKillClient, "resource", (void), ixi);
  2617. case 'l':
  2618.     DO("lastknownrequestprocessed", XLastKnownRequestProcessed, oul);
  2619.     DO1("loadfont", XLoadFont, "name", okeepfo, ist);
  2620. #if 0
  2621.     DO("lockdisplay", XLockDisplay, (void));
  2622. #endif
  2623.     DO1("lowerwindow", XLowerWindow, "window", (void), iwi);
  2624. case 'm':
  2625.     DO1("mapraised", XMapRaised, "window", (void), iwi);
  2626.     DO1("mapsubwindows", XMapSubwindows, "window", (void), iwi);
  2627.     DO1("mapwindow", XMapWindow, "window", (void), iwi);
  2628.     DO1("maskevent", myMaskEvent, "event_mask", (void), isem);
  2629.     DO("maxrequestsize", XMaxRequestSize, olo);
  2630.     DO5("moveresizewindow", XMoveResizeWindow,
  2631.         "window x y width height", (void), iwi, iin, iin, iui, iui);
  2632.     DO3("movewindow", XMoveWindow, "window x y", (void), iwi, iin, iin);
  2633. case 'n':
  2634.     DO("nextevent", myNextEvent, (void));
  2635.     DO("nextrequest", XNextRequest, oul);
  2636.     DO("noop", XNoOp, (void));
  2637. case 'p':
  2638.     DO("peekevent", myPeekEvent, (void));
  2639.     DO("pending", XPending, oin);
  2640. #if XlibSpecificationRelease - 6 >= 0
  2641.     DO1("processinternalconnection", XProcessInternalConnection, "fd",
  2642.         (void), iin);
  2643. #endif /* XlibSpecificationRelease - 6 >= 0 */
  2644.     DO("protocolrevision", XProtocolRevision, oin);
  2645.     DO("protocolversion", XProtocolVersion, oin);
  2646. case 'q':
  2647.     DO("qlength", XQLength, oin);
  2648. case 'r':
  2649.     DO1("raisewindow", XRaiseWindow, "window", (void), iwi);
  2650.     DO1("removefromsaveset", XRemoveFromSaveSet, "window", (void), iwi);
  2651.     DO4("reparentwindow", XReparentWindow,
  2652.         "window parent x y", (void), iwi, iwi, iin, iin);
  2653.     DO("resetscreensaver", XResetScreenSaver, (void));
  2654.     DO3("resizewindow", XResizeWindow,
  2655.         "window width height", (void), iwi, iui, iui);
  2656.     DO("resourcemanagerstring", XResourceManagerString, ost);
  2657.     DO1("rootwindow", XRootWindow, "screen_number", owi, isn);
  2658.     DO1("rotatebuffers", XRotateBuffers, "rotate", (void), iin);
  2659. case 's':
  2660.     DO("screencount", XScreenCount, oin);
  2661.     DO2("selectinput", XSelectInput,
  2662.         "window event_mask", (void), iwi, isem);
  2663.     DO("servervendor", XServerVendor, ost);
  2664.     DO1("setaccesscontrol", XSetAccessControl, "mode", (void), isacarg);
  2665.     DO2("setarcmode", XSetArcMode, "gc arc_mode", (void), igc, isamarg);
  2666.     DO2("setbackground", XSetBackground,
  2667.         "gc background", (void), igc, ipx);
  2668.     DO2("setclipmask", XSetClipMask, "gc pixmap", (void), igc, ipi);
  2669.     DO3("setcliporigin", XSetClipOrigin,
  2670.         "gc clip_x_origin clip_y_origin", (void), igc, iin, iin);
  2671.     DO1("setclosedownmode", XSetCloseDownMode,
  2672.         "close_mode", (void), iscdmarg);
  2673.     DO4("setdashes", XSetDashes,
  2674.         "gc dash_offset dash_list n", (void), igc, iin, ist, iin);
  2675.     DO2("setfillrule", XSetFillRule, "gc fill_rule", (void), igc, isfrarg);
  2676.     DO2("setfillstyle", XSetFillStyle,
  2677.         "gc fill_style", (void), igc, isfsarg);
  2678.     DO2("setfont", XSetFont, "gc font", (void), igc, ifo);
  2679.     DO2("setforeground", XSetForeground,
  2680.         "gc foreground", (void), igc, ipx);
  2681.     DO2("setfunction", XSetFunction, "gc function", (void), igc, ifu);
  2682.     DO2("setgraphicsexposures", XSetGraphicsExposures,
  2683.         "gc graphics_exposures", (void), igc, ibo);
  2684.     DO2("seticonname", XSetIconName, "window icon_name", (void), iwi, ist);
  2685.     DO3("setinputfocus", XSetInputFocus, "focus revert_to time",
  2686.         (void), iwi, isifarg, iti);
  2687.     DO5("setlineattributes", XSetLineAttributes,
  2688.         "gc line_width line_style cap_style join_style",
  2689.         (void), igc, iui, ils, ics, ijs);
  2690.     DO2("setplanemask", XSetPlaneMask, "gc plane_mask", (void), igc, iul);
  2691.     DO4("setscreensaver", XSetScreenSaver,
  2692.         "timeout interval prefer_blanking allow_exposures",
  2693.         (void), iin, iin, ipb, iae);
  2694.     DO3("setselectionowner", XSetSelectionOwner,
  2695.         "selection owner time", (void), iat, iwi, iti);
  2696.     DO5("setstate", XSetState,
  2697.         "gc foreground background function plane_mask",
  2698.         (void), igc, ipx, ipx, ifu, iul);
  2699.     DO2("setstipple", XSetStipple, "gc stipple", (void), igc, ipi);
  2700.     DO2("setsubwindowmode", XSetSubwindowMode,
  2701.         "gc subwindow_mode", (void), igc, issmarg);
  2702.     DO2("settile", XSetTile, "gc tile", (void), igc, ipi);
  2703.     DO2("settransientforhint", XSetTransientForHint,
  2704.         "window prop_window", (void), iwi, iwi);
  2705.     DO3("settsorigin", XSetTSOrigin,
  2706.         "gc ts_x_origin ts_y_origin", (void), igc, iin, iin);
  2707.     DO2("setwindowbackground", XSetWindowBackground,
  2708.         "window background_pixel", (void), iwi, ipx);
  2709.     DO2("setwindowbackgroundpixmap", XSetWindowBackgroundPixmap,
  2710.         "window background_pixmap", (void), iwi, ipi);
  2711.     DO2("setwindowborder", XSetWindowBorder,
  2712.         "window border_pixel", (void), iwi, ipx);
  2713.     DO2("setwindowborderpixmap", XSetWindowBorderPixmap,
  2714.         "window border_pixmap", (void), iwi, ipi);
  2715.     DO2("setwindowborderwidth", XSetWindowBorderWidth,
  2716.         "window width", (void), iwi, iui);
  2717.     DO2("setwindowcolormap", XSetWindowColormap,
  2718.         "window colormap", (void), iwi, ico);
  2719.     DO3("storebuffer", XStoreBuffer,
  2720.         "bytes nbytes buffer", (void), ist, iin, iin);
  2721.     DO2("storename", XStoreName, "window window_name", (void), iwi, ist);
  2722.     DO4("storenamedcolor", XStoreNamedColor,
  2723.         "colormap color pixel flags", (void), ico, ist, ipx, isncarg);
  2724.     DO1("sync", XSync, "discard", (void), ibo);
  2725. case 'u':
  2726.     DO1("undefinecursor", XUndefineCursor, "window", (void), iwi);
  2727.     DO3("ungrabbutton", XUngrabButton,
  2728.         "button modifiers grab_window", (void), ibu, ikbm, iwi);
  2729.     DO3("ungrabkey", XUngrabKey,
  2730.         "keycode modifiers grab_window", (void), iin, ikbm, iwi);
  2731.     DO1("ungrabkeyboard", XUngrabKeyboard, "time", (void), iti);
  2732.     DO1("ungrabpointer", XUngrabPointer, "time", (void), iti);
  2733.     DO("ungrabserver", XUngrabServer, (void));
  2734.     DO1("uninstallcolormap", XUninstallColormap, "colormap", (void), ico);
  2735.     DO1("unloadfont", XUnloadFont, "font", (void), ifo);
  2736. #if 0
  2737.     DO("unlockdisplay", XUnlockDisplay, (void));
  2738. #endif
  2739.     DO1("unmapsubwindows", XUnmapSubwindows, "window", (void), iwi);
  2740.     DO1("unmapwindow", XUnmapWindow, "window", (void), iwi);
  2741. case 'v':
  2742.     DO("vendorrelease", XVendorRelease, oin);
  2743. case 'w':
  2744.     DO8("warppointer", XWarpPointer,
  2745.         "src_w dest_w src_x src_y src_width src_height dest_x dest_y",
  2746.         (void), iwi, iwi, iin, iin, iui, iui, iin, iin);
  2747.     DO1("whitepixel", XWhitePixel, "screen_number", oul, isn);
  2748.     DO2("windowevent", myWindowEvent,
  2749.         "window event_mask", (void), iwi, isem);
  2750.     DO2("withdrawwindow", XWithdrawWindow,
  2751.         "window screen_number", ostat, iwi, isn);
  2752.     DO6("writebitmapfile", XWriteBitmapFile,
  2753.         "filename bitmap width height x_hot y_hot",
  2754.         (void), ist, ipi, iui, iui, iin, iin);
  2755.     }
  2756.     return False;
  2757. }
  2758.  
  2759. static void
  2760. usage(listfuncs)
  2761. register const Bool    listfuncs;
  2762. {
  2763.     (void) fprintf(stderr, "%s: usage is %s ", progname, progname);
  2764.     (void) fprintf(stderr, "[-int] ");
  2765.     (void) fprintf(stderr, "[-frame] ");
  2766.     (void) fprintf(stderr, "[-verbose] ");
  2767.     (void) fprintf(stderr, "[-display displayname] ");
  2768.     (void) fprintf(stderr, "[function [arg...]] ");
  2769.     if (strchr(elsieid, '\t') != NULL)
  2770.         (void) fprintf(stderr, "# %s", strchr(elsieid, '\t') + 1);
  2771.     (void) fprintf(stderr, "\n");
  2772.     if (listfuncs) {
  2773.         (void) fprintf(stderr, " functions:\n");
  2774.         (void) try(dump);
  2775.     }
  2776.     exit(1);
  2777. }
  2778.  
  2779. static char **
  2780. getfields(cp)
  2781. register char * cp;
  2782. {
  2783.     register char *        dp;
  2784.     register int        nsubs;
  2785.     register int        len;
  2786.     static char **        array;
  2787.     static char *        copyp;
  2788.  
  2789.     cp = nonnull(cp);
  2790.     len = strlen(cp);
  2791.     copyp = erealloc(copyp, len + 1);
  2792.     array = (char **) erealloc((char *) array, (len + 1) * sizeof *array);
  2793.     (void) strcpy(copyp, cp);
  2794.     nsubs = 0;
  2795.     for ( ; ; ) {
  2796.         while (isascii(*cp) && isspace(*cp))
  2797.             ++cp;
  2798.         if (*cp == '\0' || *cp == '#')
  2799.             break;
  2800.         array[nsubs++] = dp = cp;
  2801.         do {
  2802.             if ((*dp = *cp++) != '"')
  2803.                 ++dp;
  2804.             else while ((*dp = *cp++) != '"')
  2805.                 if (*dp != '\0')
  2806.                     ++dp;
  2807.                 else    wild2exit("misquoted line", copyp);
  2808.         } while (*cp != '\0' && *cp != '#' &&
  2809.             (!isascii(*cp) || !isspace(*cp)));
  2810.         if (isascii(*cp) && isspace(*cp))
  2811.             ++cp;
  2812.         *dp = '\0';
  2813.     }
  2814.     array[nsubs] = NULL;
  2815.     return array;
  2816. }
  2817.  
  2818. static char *
  2819. getline()
  2820. {
  2821.     register int    used;
  2822.     register int    c;
  2823.     static char *    buf;
  2824.     static int    avail;
  2825.  
  2826.     used = 0;
  2827.     for ( ; ; ) {
  2828.         c = getchar();
  2829.         if (c == EOF || c == '\0' || !isascii(c))
  2830.             return NULL;
  2831.         if (used >= avail)
  2832.             buf = erealloc(buf, ++avail);
  2833.         if (c == '\n') {
  2834.             if (used > 0 && buf[used - 1] == '\r')
  2835.                 --used;
  2836.             buf[used] = '\0';
  2837.             break;
  2838.         }
  2839.         buf[used++] = c;
  2840.     }
  2841.     return buf;
  2842. }
  2843.  
  2844. static void
  2845. handle(ac, av)
  2846. register const int            ac;
  2847. register const char * const * const    av;
  2848. {
  2849.     argfuncname = av[0];
  2850.     v = &av[1];
  2851.     n = ac - 1;
  2852.     if (try(mull))
  2853.         spnl(True);
  2854.     else    wild2exit("function name", av[0]);
  2855. }
  2856.  
  2857. static int
  2858. doerror(disp, eep)
  2859. Display *    disp;
  2860. XErrorEvent *    eep;
  2861. {
  2862.     char    buffer[512];
  2863.  
  2864.     (void) XGetErrorText(disp, eep->error_code, buffer, sizeof buffer);
  2865.     (void) fprintf(stderr, "\n%s: %s\n", progname, buffer);
  2866.     return 0;
  2867. }
  2868.  
  2869. int
  2870. main(argc, argv)
  2871. int    argc;
  2872. char *    argv[];
  2873. {
  2874.     register int    argn;
  2875.     register char * dispname;
  2876.  
  2877.     progname = argv[0];
  2878.     dispname = NULL;
  2879.     argn = 1;
  2880.     while (argn < argc)
  2881.         if (csequal(argv[argn], "--")) {
  2882.             ++argn;
  2883.             break;
  2884.         } else if (csequal(argv[argn], "-display")) {
  2885.             ++argn;
  2886.             if (argn >= argc)
  2887.                 wildexit(
  2888.                     "use of -display without displayname");
  2889.             else    dispname = argv[argn++];
  2890.         } else if (csequal(argv[argn], "-int")) {
  2891.             ++argn;
  2892.             intflag = True;
  2893.         } else if (csequal(argv[argn], "-frame")) {
  2894.             ++argn;
  2895.             frameflag = True;
  2896.         } else if (csequal(argv[argn], "-verbose")) {
  2897.             ++argn;
  2898.             verboseflag = True;
  2899.         } else if (csequal(argv[argn], "="))
  2900.             usage(True);
  2901.         else if (argv[argn][0] == '-')
  2902.             usage(False);
  2903.         else    break;
  2904.     display = XOpenDisplay(dispname);
  2905.     if (display == 0) {
  2906.         (void) fprintf(stderr, "%s: XOpenDisplay errno %d\n",
  2907.             progname, errno);
  2908.         wildrexit("opening display");
  2909.     }
  2910.     default_screen_number = XDefaultScreen(display);
  2911.     default_root_window = XDefaultRootWindow(display);
  2912.     default_gc = XDefaultGC(display, default_screen_number);
  2913.     default_colormap = XDefaultColormap(display, default_screen_number);
  2914.     black_pixel = XBlackPixel(display, default_screen_number);
  2915.     white_pixel = XWhitePixel(display, default_screen_number);
  2916.     single = (argc != argn);
  2917.     if (single)
  2918.         handle(argc - argn, &argv[argn]);
  2919.     else {
  2920.         interactive = isatty(fileno(stdin));
  2921.         if (interactive) {
  2922.             (void) XSetErrorHandler(doerror);
  2923.             (void) setjmp(env);
  2924.         }
  2925.         for ( ; ; ) {
  2926.             register char *        buf;
  2927.             register char **    fields;
  2928.             register int        nfields;
  2929.  
  2930.             buf = getline();
  2931.             if (buf == NULL)
  2932.                 break;
  2933.             fields = getfields(buf);
  2934.             for (nfields = 0; fields[nfields] != NULL; ++nfields)
  2935.                 continue;
  2936.             if (nfields == 0)
  2937.                 continue;
  2938.             handle(nfields, fields);
  2939.             if (ferror(stdout) || fflush(stdout))
  2940.                 break;
  2941.             if (interactive && display != NULL)
  2942.                 XSync(display, False);
  2943.         }
  2944.     }
  2945.     interactive = False;
  2946.     if (display != NULL)
  2947.         XSync(display, False);
  2948.     if (ferror(stdin))
  2949.         wildrexit("reading");
  2950.     if (ferror(stdout) || fflush(stdout) ||
  2951.         ferror(stderr) || fflush(stderr))
  2952.             wildrexit("writing");
  2953.     return 0;
  2954. }
  2955.